Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Djinous 45
8 years ago

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

Log in to vote
0
Answered by
BlackJPI 2658 Snack Break Moderation Voter Community Moderator
8 years ago

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)
0
Like this? h.Died:connect(function() player.leaderstats.Streak.Value = 0 end) Djinous 45 — 8y
0
Because that seems to be wrong. Djinous 45 — 8y
0
Like it isn't working at all? BlackJPI 2658 — 8y
Ad

Answer this question