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

Why does the Spree leaderstat not get reset?

Asked by 8 years ago

I have a short script here, it's meant to reset the "Spree" leaderstat of a player to 0 when it dies. It doesn't reset.

PPS = game:GetService("PointsService")
game.Players.PlayerAdded:connect(function(player)
    counter = Instance.new("NumberValue",player)
    counter.Name = "Counter"
    counter.Changed:connect(function(item)
        if counter.Value >= 10 then
            counter.Value = 0
            player.leaderstats.FPoints.Value = player.leaderstats.FPoints.Value +1
            PPS:AwardPoints(player.userId,1)
        end
    end)
    while wait() do if player.Character ~= nil then break end end
    player.Character.Humanoid.Died:connect(function() counter.Value = 0 player.leaderstats.Spree.Value = 0 end)
end)

1 answer

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
8 years ago

You are only getting the first character. Once the character dies and another character is created, it doesn't care about the new one. Connect to the character with player.CharacterAdded

local PPS=game:GetService("PointsService")
game.Players.PlayerAdded:connect(function(player)
    local counter=Instance.new("NumberValue",player)
    counter.Name="Counter"
    counter.Changed:connect(function(item)
        if counter.Value>=10 then
            counter.Value=0
            player.leaderstats.FPoints.Value=player.leaderstats.FPoints.Value+1
            PPS:AwardPoints(player.UserId,1)
        end
    end)
    player.CharacterAdded:connect(function(character)
        character:WaitForChild("Humanoid").Died:connect(function()
            counter.Value=0
            player.leaderstats.Spree.Value=0
        end)
    end)
end)

It also seems that you're using leaderstats and its elements but not creating them in this PlayerAdded connection. I recommend only using one connection to PlayerAdded.

0
So this script will reset the stat to zero no matter how many deaths occur? Also, This script is a separate script from the script which includes creating leaderstats. fahmisack123 385 — 8y
Ad

Answer this question