generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Math.Random not working.

Previous Thread :: Next Thread 
Soulwert1337 is not online. Soulwert1337
Joined: 13 Dec 2008
Total Posts: 4814
25 Nov 2012 12:51 PM
local t = game.Workspace.Ticker
local f = game.Lighting
local w = game.Workspace.Scripts.WColor
local x = game.Workspace.Scripts.Weather.Random.Value
local n = x

while true do
wait(3)
x = math.random(1,9)
-- If x =1
if x == 1 then do
t.Text = "Work 1"
print '1'
end
-- If x =2
if x == 2 then do
t.Text = "Work 2"
print '2'
end
-- If x =3
if x == 3 then do
t.Text = "Work 3"
print '3'
end
end
end
end
end

I am trying to have every few seconds for a random action to happen, but it keeps giving me one and a bunch of errors. Can someone help me fix this?
Report Abuse
Xnite515 is not online. Xnite515
Joined: 18 Feb 2011
Total Posts: 22763
25 Nov 2012 12:52 PM
change x to another variable you didn't use.
Report Abuse
TrueSoulWolf is not online. TrueSoulWolf
Joined: 02 Apr 2011
Total Posts: 460
25 Nov 2012 12:55 PM
Yeah, change one of the x variables to something else.
Report Abuse
BrockRocksYourSocks is not online. BrockRocksYourSocks
Joined: 22 Nov 2009
Total Posts: 5338
25 Nov 2012 12:56 PM
local t = game.Workspace.Ticker
local f = game.Lighting
local w = game.Workspace.Scripts.WColor
local x = game.Workspace.Scripts.Weather.Random.Value
local n = x

while true do
wait(3)
x = math.random(1,9)
-- If x =1
if x == 1 then
t.Text = "Work 1"
print("1")
-- If x =2
elseif x == 2 then
t.Text = "Work 2"
print("2")
-- If x =3
elseif x == 3 then
t.Text = "Work 3"
print("3")
end
end
end
end
end
Report Abuse
MikeAnIkes is not online. MikeAnIkes
Joined: 13 Mar 2010
Total Posts: 1581
25 Nov 2012 12:56 PM
remove all the 'do's after the if statements, they aren't wrong but I'm guessing you didn't mean to have them. Also, I think you want to use elseif statements here. Here:
local t = game.Workspace.Ticker
local f = game.Lighting
local w = game.Workspace.Scripts.WColor
local x = game.Workspace.Scripts.Weather.Random
local n = x

while true do
wait(3)
x.Value = math.random(1,9)
-- If x =1
if x.Value == 1 then
t.Text = "Work 1"
print '1'
elseif x.Value == 2 then
t.Text = "Work 2"
print '2'
elseif x.Value == 3 then
t.Text = "Work 3"
print '3'
end
end
Report Abuse
MikeAnIkes is not online. MikeAnIkes
Joined: 13 Mar 2010
Total Posts: 1581
25 Nov 2012 12:57 PM
Just so you know you cant have
x = game.Workspace.Scripts.Weather.Random
and then say
x = 10
and expect it to change Weather.Random's value, it only sets your variable 'x' to 10
Report Abuse
nrscsy is not online. nrscsy
Joined: 09 Nov 2012
Total Posts: 465
25 Nov 2012 12:57 PM
local t = workspace.Ticker
local f = game.Lighting
local w = workspace.Scripts.WColor
local x = workspace.Scripts.Weather.Random.Value

while wait(3) do
y = math.random(1,9)
-- If x =1
if x == 1 then
t.Text = "Work 1"
print("1")
-- If x =2
elseif y == 2 then
t.Text = "Work 2"
print("2")
-- If x =3
elseif y == 3 then
t.Text = "Work 3"
print("3")
end
end
Report Abuse
nrscsy is not online. nrscsy
Joined: 09 Nov 2012
Total Posts: 465
25 Nov 2012 12:58 PM
If you are really weird and still want to use X inside the loop, use local x.
Report Abuse
MikeAnIkes is not online. MikeAnIkes
Joined: 13 Mar 2010
Total Posts: 1581
25 Nov 2012 01:04 PM
@nrscsy Your method wouldn't work because
a) It has all the problems other than x being called twice
b) I think he wants to change the Weather.Random's actual value
c) You didn't change the 'if x==' statements to 'if y==' statements.
Report Abuse
nrscsy is not online. nrscsy
Joined: 09 Nov 2012
Total Posts: 465
25 Nov 2012 01:06 PM
I had forggoten one x == change, sorry about that.
I don't spot any problems, the script seems fine.
He can later on apply y to the weather value, no problem.
Report Abuse
Xnite515 is not online. Xnite515
Joined: 18 Feb 2011
Total Posts: 22763
25 Nov 2012 01:10 PM
local t = game.Workspace.Ticker
local f = game.Lighting
local w = game.Workspace.Scripts.WColor
local y = game.Workspace.Scripts.Weather.Random.Value
local n = y

function msg()
local t = Instance.new("Message", workspace)
end


while wait(3) do
x = math.random(1,9)
-- If x =1
if x == 1 then do
msg()
t.Text = "Work "..x
print(x)
end
-- If x =2
elseif x == 2 then do
msg()
t.Text = "Work "..x
print(x)
end
-- If x =3
elseif x == 3 then do
msg()
t.Text = "Work "..x
print(x)
end
end
end
Report Abuse
Soulwert1337 is not online. Soulwert1337
Joined: 13 Dec 2008
Total Posts: 4814
25 Nov 2012 01:41 PM
Thanks, the elseif change made it work. c:
Report Abuse
ElectricBlaze is not online. ElectricBlaze
Joined: 18 Jul 2011
Total Posts: 22930
25 Nov 2012 02:02 PM
See, I told you guys that the elseif change would make it work.

http://wiki.roblox.com/index.php/User:ElectricBlaze
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image