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

My leaderstats will not show up anymore?

Asked by 8 years ago
Edited 8 years ago

This code was working until I changed it completely to another code. But I decided to go back to the below code and now it won't even show up on the leaderstats in game. It's suppose to display and also save upon leaving the game. The script is in ServiceScriptService as it was before when it worked.

scoreKey = "PlayerScore"

game.Players.PlayerAdded:connect(function(player)

     local leaderstats = Instance.new("Model")
     leaderstats.Name = "leaderstats"
     leaderstats.Parent = player

     local money = Instance.new("IntValue") --We create a new IntValue
     money.Name = "Money" --this is the name you want the leader-stat to be when it shows up in-game.
     money.Value = 100 --this is the value of money the new player starts out with. To change this, you can add some more code (shown later)
     money.Parent = leaderstats -- Set the money object as a child of the leaderstats object.




if player:LoadNumber(scoreKey) >= -1 then --If score is less than 0 then
          score.Value = 0 --Score will equal 0
        else --otherwise
          score.Value = player:LoadNumber(scoreKey) --It will equal the saved number.
       end
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    if player:FindFirstChild("leaderstats") then
        if player.leaderstats.Money.Value == 0  then --If Money value equals 0 then
            player:SaveNumber(scoreKey, -1) --Save the money as -1
        else --Otherwise
            player:SaveNumber(scoreKey, player.leaderstats.Money.Value)   --Save it as you have it.
    end
end)

1 answer

Log in to vote
0
Answered by 8 years ago
Edited 8 years ago

There were a few parts where end wasn't used appropriately or it was missing. Here ya go.

scoreKey = "PlayerScore"

game.Players.PlayerAdded:connect(function(player)

     local leaderstats = Instance.new("Model")
     leaderstats.Name = "leaderstats"
     leaderstats.Parent = player

     local money = Instance.new("IntValue") --We create a new IntValue
     money.Name = "Money" --this is the name you want the leader-stat to be when it shows up in-game.
     money.Value = 100 --this is the value of money the new player starts out with. To change this, you can add some more code (shown later)
     money.Parent = leaderstats -- Set the money object as a child of the leaderstats object.




if player:LoadNumber(scoreKey) >= -1 then --If score is less than 0 then
          score.Value = 0 --Score will equal 0
        else --otherwise
          score.Value = player:LoadNumber(scoreKey) --It will equal the saved number.
    end
end)

game.Players.PlayerRemoving:connect(function(player)
    if player:FindFirstChild("leaderstats") then
        if player.leaderstats.Money.Value == 0  then --If Money value equals 0 then
            player:SaveNumber(scoreKey, -1) --Save the money as -1
        else --Otherwise
            player:SaveNumber(scoreKey, player.leaderstats.Money.Value)   --Save it as you have it.
        end
    end
end)


0
Yep. Not enough ends. Meltdown81 309 — 8y
0
Thank you it works again. MatthewLickster 15 — 8y
0
No problem. Brinceous 85 — 8y
Ad

Answer this question