Resetting leaderboard timer after death

So i have this script:

game.Players.PlayerAdded:connect(function(player)
local Stats = Instance.new(“Model”, player)
Stats.Name = “leaderstats”
local Timer = Instance.new(“IntValue”, Stats)
Timer.Name = “Time”
Timer.Value = 0
while true do
wait(1)
Timer.Value = Timer.Value +1
end
end)

and i need help on making a script where after you die your timer resets to 0.

1 Like

Use the Humanoid.Died event:

player.CharacterAdded:Connect(function(character)
    character.Humanoid.Died:Connect(function()
     -- Do stuff that reset the stat
    end)
end) 

I gave you the exact script you asked for on a previous post by the way, as that previous post solves this posts question as well. Before making a new post you should read through your older posts

.

Could i ask where to put this script?

You would insert it like this:

game.Players.PlayerAdded:connect(function(player)
local Stats = Instance.new(“Model”, player)
Stats.Name = “leaderstats”
local Timer = Instance.new(“IntValue”, Stats)
Timer.Name = “Time”
Timer.Value = 0
while true do
wait(1)
Timer.Value = Timer.Value +1
end
player.CharacterAdded:Connect(function(character)
character.Humanoid.Died:Connect(function()
player.leaderstats.Time.Value = 0
end)
end) 
end)
1 Like

Sorry about the many replies, i’m new to scripting.
About the code you told me to insert, do i need to add any other scrips to it? I tried that script and the time leaderboard didn’t show up.
Capture

For the script I gave you, that script goes in any part that you want touched to start the timer.

You should throw a script like this in serverscriptservice

game.Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder",player)
	leaderstats.Name = "leaderstats"
	
	local timer = Instance.new("NumberValue",leaderstats)
	timer.Name = "Timer"
end)

and this script below inside of a part

Ahh thank you so much! It’s all good now :slight_smile: