While loop speeding up/wait() not working

I don’t know exactly what the problem is but it appears as though my while loop is speeding up. Here is the code:

function startTimer()	
	while brake==false do
		wait(.1)
		timer=timer+.1
		print(timer)
		if timer> 1.2 then
			lateThrow()
		end
	end
end

The timer starts when the player equips the frisbee

Here is how it is supposed to work:

However, when the players get close to each other, the timer speeds up a bunch and this happens:

I don’t know how your whole script works but if this is a server script and timer is defined outside of the function, calling startTimer() multiple times will cause the timer to speed up, because your function will run multiple times.

This is a server script but startTimer() is only called once when the frisbee is equipped and I set timer=0 just before calling it. I guess putting timer=0 in startTimer() makes more sense but it should have the same result.

I fixed it by adding a break in the if statement

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.