My idle timer isn't working

Hello! I created an idle timer, however, it isn’t working properly.

Expected behavior:

After 5 seconds of wait(), while the player has been idle for 5 seconds, the timer will show. If the player does any input of any kind, it will hide the timer and put the clock at 0.

The problem:

The expected behavior would work around 1-4 times, but then after that, Roblox will think the player is idle after like 1 second of moving.

Video of problem:

The Code:

local timePassed = 0

local uis = game:GetService("UserInputService")
	script.Parent:TweenPosition(, 0, 1.2, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.2)
	timePassed = 0

	while wait(1) do
		timePassed += 1
		if timePassed > 5 then
			script.Parent:TweenPosition(, 0, 1, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Linear, 0.2)

If you can help, please let me know. Thanks, WE

1 Like

Every time one of your inputs end you create another infinite loop that increases your timePasses by 1 per second effectivly accelerating time for you.
Just get rid if your InputEnded and it should work like you expect.


Well how would I make the clock appear then?