Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why does my game crash when I test my game?

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

1 comment

0

You forgot to add a 'wait' into the loop.

1 answer

✓ Accepted answer

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

1 comment

0

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.