How can i make a timer without bugs?

So i tried to make a timer couple of times and it started to give me some headaches cuz i really dont know what to do now,im making an timer and when it reaches 0 Turn changes but the thing is bugs pop out of nowhere like multiple timers spawn which i managed to fix but i cannot fix whenever i make a choice(in game) right about the timer reaches 0 Game skips 2 Turns instead of 1 i might overshared some information but at most basic core how can i make a timer that i can stop and restart whenever i want which basics or forums i should learn?(im newbie)

2 Likes

You’ll need to provide the code you are using, not only for the timer but also wherever you are calling any functions from.

1 Like
remotes.SendEvent.OnServerEvent:Connect(function(plr,arg)
	if arg =="P" then
		if not gameActive then return end
		if plr == turnTable[turnIndex] then
			timerActive = false
			placeCard(plr)
			gameModule.turnChange()
		end

	elseif arg =="D" then
		if not gameActive then return end
		if plr == turnTable[turnIndex] then
			gameActive = false
			timerActive = false
			destroyModule.Destroy(plr,round,score)
			gameModule.finishGame()

		end
	end

end)
function gameModule.startTimer()
	local timerRound = round 
	if timerRound ~= round or timerRuning then return end	
	timerRuning = true
	local timer = timerStart
	
	while timer > 0 and timerActive do
		if timerActive == false then return end
		task.wait(1)
		timer -= 1
		if timerActive == false then return end
		for i,v in pairs(turnTable) do
			players:FindFirstChild(v.Name).PlayerGui.PlayGui.TopFrame.Timer.Text = timer
		end
		
	end
	
	timerRuning = false
	if timerRound ~= round or timerRuning then return end
	round += 1	
	gameModule.turnChange()
end
1 Like

are you saying the round is increasing twice instead of once?