The following is a very simple script, but always crashes my game when I test it. Why?
while true do
script.Parent.SpotLight.Angle = script.Parent.SpotLight.Angle +5
end
The following is a very simple script, but always crashes my game when I test it. Why?
while true do
script.Parent.SpotLight.Angle = script.Parent.SpotLight.Angle +5
end
I cannot tell you why, but games always crash when you do not wait before ending a infinite loop. This may be because it's loops an infinite amount of times and it's too much to handle/too fast. To fix this, just add a wait before the end.
while true do
script.Parent.SpotLight.Angle = script.Parent.SpotLight.Angle +5
wait() --I prefer wait() unless you would like to use wait(1), depending on how fast you want it to add 5 to the angle.
end
Lua is interpreted mostly asynchronously. That is, when the while loop, well, loops, any instructions done within the loop are not waited on for completion. If the loop loops faster than the time it takes for all instructions within an infinite loop to fully process, you get a loop that crashes ROBLOX.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
You forgot to add a 'wait' into the loop.