I’m having a problem with when a player resets their character or dies countdown starts over.
here this my problem
local countdownTime = 1 * 60
local textLabel = script.Parent.TextLabel
local function CountDown()
repeat
local minutes = math.floor(countdownTime / 60)
local seconds = countdownTime % 60
textLabel.Text = string.format("%02d : %02d", minutes, seconds)
wait(1)
countdownTime -= 1
until countdownTime <= 0
-- Kick player when time is up
game.Players.LocalPlayer:Kick("Time's up!")
end
CountDown()
Try disabling the countdown UI’s ResetOnSpawn property and I would suggest changing the local-sided script to a server-sided one because local client kicks can be bypassed easily
I would also recommend changing your repeat until loop into a for loop instead, and using another function to format the time accordingly. Using repeat until isn’t a very good or efficient way of making a countdown.
local function toMS(s)
return ("%02i:%02i"):format(s/60%60, s%60)
end
local function CountDown()
for i = countdownTime, 0, -1 do
textLabel.Text = toMS(i)
task.wait(1)
end
...
end