I was experimenting rubbles movement when being drilled, to solve this, I wanted to add a math.random onto my script, and added while true do and I receive an error.
My error:
Workspace.Drill.ParticlePart.Script:18: 'end' expected (to close 'while' at line 5) near '<eof>'
My Script:
local r = math.random(1, 100) local s = script.Parent.ParticleEmitter n = 20 wait(3) while true do if r > 0 and r < 25 then s.Size = NumberSequence.new(.25) s.Rate = n elseif r > 25 and r < 50 then s.Size = NumberSequence.new(.3) s.Rate = n elseif r > 50 and r < 75 then s.Size = NumberSequence.new(.35) s.Rate = n elseif r > 75 and r < 100 then s.Size = NumberSequence.new(.4) s.Rate = n end
What am I doing: I wanted to add a wait() on a loop command, however, I don't know what to do in order to fix the error, if there's any simpler way... please help c:
First off, the error is simply because you are missing an end to close the while loop (the end you currently have only closes the if statement). You should also move the wait to be inside of your while loop to avoid it hanging your game. As well as this, the random number will be the same value every time the loop happens. This is because you only generate the random number once at the top of the script, and it uses that same number for the rest of the script. To fix this, you should generate the random number inside of the loop. Also keep in mind if the random number is exactly equal to 25, 50, 75 or 100, it wont do anything (you need yo use <= or >=).
local s = script.Parent.ParticleEmitter n = 20 while true do wait(3) local r = math.random(1, 100) if r > 0 and r < 25 then s.Size = NumberSequence.new(.25) s.Rate = n elseif r >= 25 and r < 50 then s.Size = NumberSequence.new(.3) s.Rate = n elseif r >= 50 and r < 75 then s.Size = NumberSequence.new(.35) s.Rate = n elseif r >= 75 and r < 100 then s.Size = NumberSequence.new(.4) s.Rate = n end end