I am making a death timer and this is a segment of my script, I’ve tried remote events and all and idk what to do (this is a local script btw) I am trying to kill the player.
Your time would be much appreciated!
if currentTime == 0 then
local killEv = game:GetService("ReplicatedStorage").KillEvent
char.Humanoid.Health = 0
end
local label = script.Parent
local currentTime = 10
local player = game:GetService("Players").LocalPlayer
local char = player.Character
local function formatTime()
local hours = math.floor(currentTime / 3600)
local minutes = math.floor((currentTime - (hours * 3600))/60)
local seconds = (currentTime - (hours * 3600) - (minutes * 60))
local format = "%02d:%02d"
return format:format(minutes, seconds)
end
local function startTimer()
while true do
currentTime -= 1
label.Text = formatTime()
task.wait(1)
end
end
startTimer()
if currentTime <= 0 then
local killEv = game:GetService("ReplicatedStorage").KillEvent
char.Humanoid.Health = 0
end
local function startTimer()
while true do
currentTime -= 1
label.Text = formatTime()
if currentTime <= 0 then
-- do your thing here (kill the player, reset the timer, etc.)
break -- don't forget to break out of the loop
end
task.wait(1)
end
end
startTimer()
If you use while true do after the end , it will not run. The while true loop creates an infinite loop, and the code after it will never be executed if i am right try using RunService. i might also be false…
Just to add, your original code does actually work. You just forgot to break out of the loop after the currentTime hits 0 making the while loop run infinitely → never reaching the “if currentTime <= 0” line