My Timer is breaking

Hello,
So I have a timer script:

for i = 300,0,-1 do
			
			if Values.ClocksCollected.Value == 7 then
				if i > 60 then
					if i <= 120 then
						i = 60
					else
						i -= 60
					end
				end
			end
			
			if Values.PanelsCollected.Value == 2 then
				if i > 60 then
					if i <= 120 then
						i = 60 
					else
						i -= 60
					end
				end
			end
			Status.Value = ToMS(i)
			wait(1)
		end

It works, but when I add / remove time from the clock, the time gets removed, but the timer breaks(the clock just shows how long is left and that’s it, it doesn’t count down!
I get no errors, why does this happen??

1 Like

how much does it show of what’s left, and what is ToMS?

ToMs converts it to Minutes and seconds, but that’s irrelevant.

The timer goes down, but then it gets stuck because I subtracted time, so how do I subtract time without it breaking??

Here is the full loop:

	for i = 300,0,-1 do
			
			if Values.ClocksCollected.Value == 7 then
				if i > 60 then
					if i <= 120 then
						i = 60
					else
						i -= 60
					end
				end
			end
			
			if Values.PanelsCollected.Value == 2 then
				if i > 60 then
					if i <= 120 then
						i = 60 
					else
						i -= 60
					end
				end
			end
			if i == 269 then
				TeleportDoge(Doge,Map)
				Values.KillFeed.Value = 'Doge is here!'
				game.ReplicatedStorage.Values.GameInProgress.Value = true
				wait(1)
			end
			
			if i == 60 then
				workspace.GameMusic:Stop()
				workspace.GameMusic.Looped = false
				Values.ExitsOpen.Value = true
				TopText.Value = 'EscapeOpen'
				Doge.Character.Humanoid.WalkSpeed = 17
				Music(false,true,'EscapeMusic',false)
				OpenExits(Map,Doge)
			end
			
			
			if #PlayingPlayers <= 1 then
				break
			end
			
			if not table.find(PlayingPlayers,Doge) then
				break
			end
			Status.Value = ToMS(i)
			wait(1)
		end

i think the issue is that if you change the value of i, the engine thinks you have converted it into a constant, and therefore keeps it’s value. i wonder what would happen if you get a different value for I, but still keep I looping or changed to an infinite while loop.

Then how can I subtract 60 seconds from i, so that it continues going from the new value?

are you changing it manually or is it the code that changes it?
Also,

if i > 60 then
	if i <= 120 then
		i = 60
	else
		i -= 60
	end
end

is almost completely useless because when i > 120, it will subtract 60, after wich i < 120, after wich it will be set to 60, after wich it will be == 60, and not greater than 60.

2 Likes

OMG LOL.

That’s my problem! I forgot to set the value to 0!
So the timer keeps getting set to 60, thanks so much!