|
| 26 Nov 2011 11:25 AM |
I'm trying to make it so that a ball chooses to move in one of 9 different ways, so I try some mathrandom stuff, and nothing happens.
local m = math.random(1,9) while true do if m == 1 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.5, 0, 1) end while true do if m == 2 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(1, 0, 0.5) end while true do if m == 3 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.5, 0, 0.5) end while true do if m == 4 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(1, 0, 1) end while true do if m == 5 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.75, 0, 0.75) end while true do if m == 6 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.5, 0, 0.75) end while true do if m == 7 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.75, 0, 0.5) end while true do if m == 8 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.75, 0, 1) end while true do if m == 9 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(1, 0, 0.75) end
What's the solution? |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 26 Nov 2011 11:30 AM |
instead of doing all of those, just do one 'while true do' at the beginning, and make each if except for the first one 'else if' and put all of the ends at the end of the script. like so:
m = math.random(1,9) while true do if m == 1 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.5, 0, 1) else if m == 2 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(1, 0, 0.5) else if m == 3 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.5, 0, 0.5) else if m == 4 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(1, 0, 1) else if m == 5 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.75, 0, 0.75) else if m == 6 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.5, 0, 0.75) else if m == 7 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.75, 0, 0.5) else if m == 8 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.75, 0, 1) else if m == 9 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(1, 0, 0.75) end end end end end end end end end end
|
|
|
| Report Abuse |
|
|
MrChubbs
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 4969 |
|
|
| 26 Nov 2011 11:30 AM |
--local m = math.random(1,9) This defines it once and only once. while true do local m = math.random(1,9) if m == 1 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.5, 0, 1) end while true do if m == 2 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(1, 0, 0.5) end while true do if m == 3 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.5, 0, 0.5) end while true do if m == 4 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(1, 0, 1) end while true do if m == 5 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.75, 0, 0.75) end while true do if m == 6 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.5, 0, 0.75) end while true do if m == 7 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.75, 0, 0.5) end while true do if m == 8 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.75, 0, 1) end while true do if m == 9 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(1, 0, 0.75) end or
while wait(1) do local X = math.random(0,1) local Y = math.random(0,1) local Z = math.random(0,1) script.Parent.Velocity = Vector3.new(X*5, Y*5, Z*5) end |
|
|
| Report Abuse |
|
|
|
| 26 Nov 2011 11:31 AM |
Woahwoah! Only one loop!
First, look through and any spot you see a:
end while true do if
Replace all of that with 'elseif' (no apostrophe)
Next, at the very end of the script, add an end
Now delete wherever it says 'wait(0.01)'
Then put a wait(.01) after the first while true do
Last, put the math.random thing after the first while true do. |
|
|
| Report Abuse |
|
|
|
| 26 Nov 2011 11:32 AM |
| You guys should use elseif and only one loop. |
|
|
| Report Abuse |
|
|
|
| 26 Nov 2011 11:34 AM |
| killjoy's works. I can't believe I forgot to use "else"! >_< |
|
|
| Report Abuse |
|
|
killjoy37
|
  |
| Joined: 27 Aug 2008 |
| Total Posts: 2821 |
|
|
| 26 Nov 2011 11:35 AM |
| Yay, im glad mine worked first try. (It's a rare event) |
|
|
| Report Abuse |
|
|
|
| 26 Nov 2011 11:36 AM |
local m = math.random(1,9) while wait() do if m == 1 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.5, 0, 1) elseif m == 2 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(1, 0, 0.5) elseif m == 3 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.5, 0, 0.5) elseif m == 4 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(1, 0, 1) elseif m == 5 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.75, 0, 0.75) elseif m == 6 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.5, 0, 0.75) elseif m == 7 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.75, 0, 0.5) elseif m == 8 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(0.75, 0, 1) elseif m == 9 then wait(0.01) script.Parent.Position = script.Parent.Position + Vector3.new(1, 0, 0.75) end end |
|
|
| Report Abuse |
|
|
MrChubbs
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 4969 |
|
| |
|
MrChubbs
|
  |
| Joined: 14 Oct 2010 |
| Total Posts: 4969 |
|
|
| 26 Nov 2011 11:37 AM |
Forgot to add the -1 XD
while wait(1) do local X = math.random(-1,1) local Y = math.random(-1,1) local Z = math.random(-1,1) script.Parent.Velocity = Vector3.new(X*5, Y*5, Z*5) end |
|
|
| Report Abuse |
|
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 26 Nov 2011 11:39 AM |
LOl I'd do it like this:
local part = FILLINOBJECT local directions = { Vector3.new(0, 6, 0); Vector3.new(0, -5, 0; Vector3.new(6, 6, 0) --etc..... }
while wait() do part.CFrame = part.CFrame + directions[math.random(1, #directions)] end
~Myrco; Music lover, nederlands/dutch and a scripter |
|
|
| Report Abuse |
|
|
|
| 26 Nov 2011 11:49 AM |
I'll shorten it up:
function move(x,z) script.Parent.CFrame = script.Parent.CFrame + Vector3.new(x,0,z) end
while wait() do local m = math.random(9) if m == 1 then move(.5,1) elseif m == 2 then move(1,.5) elseif m == 3 then move(.5,.5) elseif m == 4 then move(1,1) elseif m == 5 then move(.75,.75) elseif m == 6 then move(.5,.75) elseif m == 7 then move(.75,.5) elseif m == 8 then move(.75,1) elseif m == 9 then move(1,.75) end end |
|
|
| Report Abuse |
|
|