Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why does my game crash when I test my game?

Asked by 10 years ago

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
0
You forgot to add a 'wait' into the loop. TheeDeathCaster 2368 — 10y

1 answer

Log in to vote
4
Answered by
Relatch 550 Moderation Voter
10 years ago

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
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. adark 5487 — 10y
Ad

Answer this question