Timer gets glitched outs

Hey, so I made a timer, when the lava gets at a certain level, the timer gets restarted, but however sometime the timer glitches out by telling the wrong second

local model = game.Workspace.Doomspire
local messageText = ("regenerating")
local debris = game:GetService("Debris")
local backup = model:clone()

while true do
	task.wait(1)
	for i = 600,0,-1 do
		script.Parent.Text = i
		wait(1)
			
		if game.Workspace.Part.Position.Y >= -49.5 then
			game.Workspace.Part.Position = Vector3.new(-81, -175.5, -71.5)
			game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent"):FireAllClients()
			game.Workspace.Part.Lava.Enabled = false

			game.ServerScriptService.lose.Enabled = false
			model:remove()
			wait(2)

			model = backup:clone()
			model.Parent = game.Workspace
			model:makeJoints()
			i = 600
			script.Parent.Text = i

			game.ServerScriptService.lose.Enabled = true
			
			game.Workspace.Part.Lava.Enabled = true
			
			
				
		end
	end
end
local screen = script.Parent
game:GetService("ReplicatedStorage"):WaitForChild("sensors").OnClientEvent:Connect(function()
	screen:TweenPosition(UDim2.new(0.983, 0,1.189, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 2, true)
	wait(6)
	screen:TweenPosition(UDim2.new(0.983, 0,100, 0), Enum.EasingDirection.Out, Enum.EasingStyle.Sine, 2, false)
end)```
1 Like

Update, the timer does not reset at all

The issue you’re facing with the timer telling the wrong second is due to the way you’re attempting to reset the timer. In your code, you have a for loop that counts down from 600 to 0, but inside that loop, you have i = 600 , which doesn’t actually reset the loop counter.

To fix this issue, you need to change your approach. Instead of using a for loop to count down the timer, you can use a variable to track the remaining time and decrement it manually.

local model = game.Workspace.Doomspire
local messageText = "regenerating"
local debris = game:GetService("Debris")
local backup = model:clone()

local remainingTime = 600  -- Initial timer value

while true do
	task.wait(1)
	remainingTime = remainingTime - 1  -- Decrement the remaining time

	script.Parent.Text = remainingTime

	if game.Workspace.Part.Position.Y >= -49.5 then
		game.Workspace.Part.Position = Vector3.new(-81, -175.5, -71.5)
		game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent"):FireAllClients()
		game.Workspace.Part.Lava.Enabled = false

		game.ServerScriptService.lose.Enabled = false
		model:remove()
		wait(2)

		model = backup:clone()
		model.Parent = game.Workspace
		model:makeJoints()
		remainingTime = 600  -- Reset the remaining time
		script.Parent.Text = remainingTime

		game.ServerScriptService.lose.Enabled = true

		game.Workspace.Part.Lava.Enabled = true
	end
end

Thanks it works but I have one more problem

Everytime a team wins the lava is set to a very low Y axis which I do not want how could I fix this?

Lava’s original position

Script

	elseif #spawnfolder4:GetChildren() > 1 and #spawnfolder2:GetChildren() < 1  and #spawnfolder3:GetChildren() < 1 and #spawnFolder:GetChildren() < 1 then do
			game:GetService("ReplicatedStorage"):WaitForChild("yellow"):FireAllClients()
			game.Workspace.Part.Position += Vector3.new(-81, -157.5, -71.5)
			game.ServerScriptService.lose.Enabled = false
			model:remove()
			local teams = game:GetService("Teams"):GetChildren()

			game.Players.PlayerAdded:Connect(function(player)
				for i,player in pairs(game.Players:GetPlayers()) do
					if player then 
						local randomteam = teams[math.random(1, 4)]

						player.Team = randomteam
					end
				end
			end)
			wait()
			wait(5)
			model = backup:clone()
			model.Parent = game.Workspace
			model:makeJoints()
			game.ServerScriptService.lose.Enabled = true

Out come