I have a save stats script, but it does not work right! It saves my point but does not save my rebirth, why? For example, if I have 100 points, and I rebirth, and I left the game, and later if I join back it will say I have 100 points and 0 rebirths, why? Another problem is that, whenever I rebirth and it will clear my points and give me 1 rebirth, but when I click on a block that gives me points, it automatically start me with 100 points, why? For example, if I rebirth I will have 1 rebirth and it will clear my points, but when I click on a block that gives me 2 points, I will automatically have 102 points, why?
Here is the save stats script
function onPlayerEntered(player) wait() player:WaitForDataReady() repeat wait() until player:FindFirstChild("leaderstats") if player.DataReady then if player:findFirstChild("leaderstats") then local score = player.leaderstats:GetChildren() for i = 1,#score do local ScoreLoaded = player:LoadNumber(score[i].Name) wait() if ScoreLoaded ~= 0 then score[i].Value = ScoreLoaded end end end end end function onPlayerLeaving(player) if player:findFirstChild("leaderstats") then local score = player.leaderstats:GetChildren() for i = 1,#score do player:SaveNumber(score[i].Name,score[i].Value) end end end game.Players.PlayerAdded:connect(onPlayerEntered) game.Players.PlayerRemoving:connect(onPlayerLeaving)
Here is the leaderstats script
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("Model") leaderstats.Name = "leaderstats" leaderstats.Parent = player local money = Instance.new("IntValue") money.Name = "LifeFormFound" money.Value = 0 money.Parent = leaderstats local Points = Instance.new("IntValue") Points.Name = "Rebirth" Points.Value = 0 Points.Parent = leaderstats end)