scoreKey = "PlayerScore"
game.Players.PlayerAdded:connect(function(player)
local stat = Instance.new("IntValue")
stat.Name = "leaderstats"
stat.Parent = player
local WinTokens = Instance.new("IntValue")
WinTokens.Name = "WinTokens"
WinTokens.Parent = stat
WinTokens.Value = player:LoadNumber(scoreKey)
end)
game.Players.PlayerRemoving:connect(function(player)
if player:FindFirstChild("leaderstats") then
player:SaveNumber(scoreKey, player.leaderstats.WinTokens.Value)
end
end)
This script is a normal script in serverscriptservice.
I read the wiki on data persistence and made this script, but it doesn't work. Whats the problem?
