|
| 21 Sep 2013 06:19 AM |
It saves and loads most of the time, but sometimes a player's stats are reset to 0. Is there anything I've left out or accidentally cut?
function onXPChanged(player, XP, Lvl) if XP.Value>=Lvl.Value * 50 and Lvl.Value < script.LevelCap.Value then XP.Value = XP.Value - Lvl.Value * 50 Lvl.Value = Lvl.Value + 1 end end
function saveScore(player, score) player:SaveNumber("Lvl", score) end
function saveScore2(player, score) player:SaveNumber("XP", score) end
function saveScore3(player, score) player:SaveNumber("GP", score) end
function loadScore(player, clickCounter) local score = player:LoadNumber("Lvl")
if score ~= 1 then clickCounter.Value = score else print("Nothing to load/score was 0") end
end
function loadScore2(player, clickCounter) local score = player:LoadNumber("XP")
if score ~= 0 then clickCounter.Value = score else print("Nothing to load/score was 0") end
end
function loadScore3(player, clickCounter) local score = player:LoadNumber("GP")
if score ~= 10 then clickCounter.Value = score else print("Nothing to load/score was 0") end
end
function onPlayerEntered(newPlayer)
local stats = Instance.new("IntValue") stats.Name = "leaderstats"
local clicks = Instance.new("IntValue") clicks.Name = "Lvl" clicks.Value = 1
local clicks2 = Instance.new("IntValue") clicks2.Name = "XP" clicks2.Value = 0
local clicks3 = Instance.new("IntValue") clicks3.Name = "GP" clicks3.Value = 10
clicks.Parent = stats clicks2.Parent = stats clicks3.Parent = stats stats.Parent = newPlayer
clicks2.Changed:connect(function() onXPChanged(newPlayer, clicks2, clicks) end) clicks.Changed:connect(function() onLevelUp(newPlayer, clicks2, clicks) end)
newPlayer:WaitForDataReady()
loadScore(newPlayer, clicks) loadScore2(newPlayer, clicks2) loadScore3(newPlayer, clicks3)
newPlayer.CharacterAdded:connect(function(c) c.Humanoid.MaxHealth = newPlayer.leaderstats.Lvl.Value * 10 + 50 end) end
function onPlayerRemoving(player) print("Attempting to save score for " .. player.Name) local stats = player:FindFirstChild("leaderstats") if (stats ~= nil) then local clicks = stats:FindFirstChild("Lvl") local clicks2 = stats:FindFirstChild("XP") local clicks3 = stats:FindFirstChild("GP") if (clicks ~= nil)and(clicks2 ~= nil)and(clicks3 ~= nil) then saveScore(player, clicks.Value) saveScore2(player, clicks2.Value) saveScore3(player, clicks3.Value) end end end
game.Players.PlayerAdded:connect(onPlayerEntered) game.Players.PlayerRemoving:connect(onPlayerRemoving) |
|
|
| Report Abuse |
|
|
| 21 Sep 2013 06:27 AM |
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)
|
|
|
| Report Abuse |
|