I am trying to find a way to have a GUI timer kill the player once it expires. The current script is below. The code at the end successfuly prints the message, but it does not kill the player. Is there a way to fix this?
local timer = script.Parent
local minutes = 1 -- minutes
local seconds = 0 -- seconds
-- Function to update the timer text
local function updateTimer()
if seconds <= 0 then
if minutes > 0 then
minutes = minutes - 1
seconds = 59
else
-- When both minutes and seconds are 0, stop the timer
minutes = 0
seconds = 0
timer.Text = "0:00"
return
end
else
seconds = seconds - 1
end
-- Formatting the timer display with a leading zero for seconds if needed
if seconds < 10 then
timer.Text = tostring(minutes)..":0"..tostring(seconds)
else
timer.Text = tostring(minutes)..":"..tostring(seconds)
end
end
-- Repeat the update every second
while minutes > 0 or seconds > 0 do
updateTimer()
wait(1)
end
-- Final timer display when it reaches 0
timer.Text = "0:00"
-- Below is the area of focus
print ("Out of time")
local Players = game:GetService("Players")
Players.PlayerAdded:Wait() -- optional
local player = Players:GetPlayers()[math.random(1, #Players:GetPlayers())]
local human = player.Character and player.Character:WaitForChild("Humanoid")
human:TakeDamage(100)