Game script timeout

Im getting an error at line 4, why is this? It only happens when it goes to true, while its false it works perfectly.

Tool = script.Parent

while true do
	if script.Parent.AboutToThrow.Value == false then
		Tool.GripPos = Vector3.new(0, 0.5, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 1, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 1.5, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 2, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 2.5, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 3, -0.3)
		Tool.Handle.bounce:Play()
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 2.5, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 2, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 1.5, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 1, -0.3)
		wait(0.05)
		else
	end
	end
1 Like

It looks like your if statement condition is never true. What you’ve created here is an infinite loop. Put a wait() in between the end of the if statement and the end of the while.

you have to put a wait after the first end also:

Tool = script.Parent

while true do
	if script.Parent.AboutToThrow.Value == false then
		Tool.GripPos = Vector3.new(0, 0.5, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 1, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 1.5, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 2, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 2.5, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 3, -0.3)
		Tool.Handle.bounce:Play()
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 2.5, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 2, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 1.5, -0.3)
		wait(0.05)
		Tool.GripPos = Vector3.new(0, 1, -0.3)
		wait(0.05)
		else
	end
    wait() -- You need a wait here
end

If a while loop runs without a wait command being executed, the loop will stop running (break). So when it goes to true, no wait command is being executed and the loop breaks.

A 100% fix for this would be to add a wait command outside the if statement.

Loops don’t terminate because they’re missing an interval. That’s where the timeout (or game crash) steps into the playing field, because the scheduler is now being told to run endless iterations of something in one go as opposed to scheduling each iteration.

2 Likes

As others have mentioned you have created an infinite loop. From looking at your code it seems like you are trying to animate something, even if your current code did work it would look very jittery moving it in increments.

Because you are trying to animate something, you would be better off using tween service.

This thread explains why you should avoid wait() and subsiquently while loops.