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)

3 comments
Yep. Not enough ends.
Thank you it works again.
No problem.