If statements and local players health

I’m trying to make it where if a local player dies something will happen. In this case I have a timer and am trying to make it where whenever the player dies the timer will reset.

local Player = Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Health = Char:WaitForChild("Humanoid").Health

local function teleport()
	local clonedgui = Player.PlayerGui:WaitForChild("Timer")
	local minutes = 0
	local seconds = 16
	repeat
		if seconds <= 0 then
			minutes = minutes - 1
			seconds = 59
		else
			seconds = seconds - 1
		end
		if seconds < 10 then
			clonedgui.TextLabel.Text = tostring(minutes)..":0"..tostring(seconds)
		else 
			clonedgui.TextLabel.Text = tostring(minutes)..":"..tostring(seconds)
		end
		if Health < 1 then
			local minutes = 0
			local seconds = 16
		end
		wait(1)
	until minutes <= 0 and seconds <= 0
end

Here I have a script which doesn’t seem to be working because whenever the player dies the timer doesn’t reset, instead it just keeps going on. I thought “if health < 1 then” or “if health == 0 then” would work but none of those options seem to be working. By the way I am using a local script in StarterPlayerScripts. Thanks.

I think Player.Character.Humanoid.Died is what you are looking for.

1 Like

You’re not updating Health variable, try Humanoid.HealthChanged for updating or rewrite code to Humanoid.Died scenario

Do you mean something like this?

if Player.Character.Humanoid.Died then
			local minutes = 0
			local seconds = 16
		end

No do this

 Player.Character.Humanoid.Died:Connect(function()
local minutes = 0
			local seconds = 16
end)
1 Like