Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Have a leaderboard stat reset to 0 on death? My function isn't working.

I have a script set up to make the leaderstat "Streak" go up by one every time you hit a checkpoint. What can I do to make it so that whenever a player dies, it goes back down to 0? I've tried a function, but it isn't working.

function ot(hit)
if hit.Parent ~= nil then
player = game.Players:playerFromCharacter(hit.Parent)
if player ~= nil then
if player.leaderstats.Stage.Value == script.Parent.Name - 1 then
h = hit.Parent:FindFirstChild("Humanoid")
if h ~= nil then
if h.Health ~= 0 then
player.leaderstats.Stage.Value = script.Parent.Name
player.leaderstats.Streak.Value = player.leaderstats.Streak.Value + 1
end end end end end end
function died()
	player.leaderstats.Streak.Value = 0
end

script.Parent.Touched:connect(ot)
h.Died:connect(died)

1 answer

You can use the Died event of humanoid in order to change the value once the player is killed:

####Example:

h.Died:connect(function()
	player.leaderstats.Stage.Value = script.Parent.Name 
	player.leaderstats.Streak.Value = player.leaderstats.Streak.Value + 1 
end)

3 comments

0

Like this? h.Died:connect(function() player.leaderstats.Streak.Value = 0 end)

0

Because that seems to be wrong.

0

Like it isn't working at all?

This discussion is preserved as it was. New answers, comments, and votes are closed.