MattJon
|
  |
| Joined: 28 Apr 2009 |
| Total Posts: 660 |
|
|
| 07 Apr 2013 07:57 PM |
When using data Persistance, is it not enough to have the leaderboard script? Do you have to have something to forcefully save a value? If so, what is it? All I have is my leaderboard with data persistance.
--------------------------------------------------------------
scoreKey = "PlayerScore" game.Players.PlayerAdded:connect(function(player) player:WaitForDataReady() -- create leaderboard local ls = Instance.new("IntValue") ls.Name = "leaderstats" ls.Parent = player --create the score stat local score = Instance.new("IntValue") score.Name = "Treasure" score.Parent = ls local ok, ret = pcall(function() return player:LoadNumber(scoreKey) end) if ok then if ret ~= 0 then score.Value = ret else print("Nothing to load/score was 0") end else print("Error:", ret) end end) game.Players.PlayerRemoving:connect(function(player) --if a player leaves before the leaderstats have been created it won't crash the script, as it's in a pcall local succ, ret = pcall(function() player:SaveNumber(scoreKey,player.leaderstats.Score) end) if succ then print("Successfully saved") else print("Saving error:", ret) end end) |
|
|
| Report Abuse |
|
|
|
| 07 Apr 2013 08:01 PM |
You might want to save at intervals, incase someone crashes and is instantly removed from the game.
But no there is no way to "force" save. Saving does not work in play solo due to the players ability to be different characters (Player1, Player2, etc). |
|
|
| Report Abuse |
|
|
MattJon
|
  |
| Joined: 28 Apr 2009 |
| Total Posts: 660 |
|
|
| 07 Apr 2013 08:03 PM |
| Well, yes but I'm asking how to save. Does it do that automatically? |
|
|
| Report Abuse |
|
|
MattJon
|
  |
| Joined: 28 Apr 2009 |
| Total Posts: 660 |
|
| |
|
FoggedOut
|
  |
| Joined: 09 Dec 2011 |
| Total Posts: 3021 |
|
|
| 07 Apr 2013 08:19 PM |
Heres what I use to save my LeaderBoard Stats. Just showing you:
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)
Yeah, its quite simple. |
|
|
| Report Abuse |
|
|
MattJon
|
  |
| Joined: 28 Apr 2009 |
| Total Posts: 660 |
|
|
| 07 Apr 2013 08:25 PM |
| Very nice. So this would be a script separate from the leaderboard? And if I wanted to save a StringValue? Would I merely change LoadNumber and SaveNumber to LoadString and SaveString? (and ya'know leaderstats to leaderstats2, or whatever personal touch I want to add) |
|
|
| Report Abuse |
|
|
FoggedOut
|
  |
| Joined: 09 Dec 2011 |
| Total Posts: 3021 |
|
|
| 07 Apr 2013 08:28 PM |
| Yes it would be seperate. If its not seperate, than its VERY hard to edit. |
|
|
| Report Abuse |
|
|
MattJon
|
  |
| Joined: 28 Apr 2009 |
| Total Posts: 660 |
|
|
| 07 Apr 2013 08:58 PM |
| That script works BEAUTIFULLY for IntValues. I am not advanced enough however to edit it for StringValues. I tried and failed. Any successful results I will reward. Please |
|
|
| Report Abuse |
|
|
FoggedOut
|
  |
| Joined: 09 Dec 2011 |
| Total Posts: 3021 |
|
|
| 07 Apr 2013 09:00 PM |
| Sorry, I eally cant make somthing like that gain but with different values. xD That script took me weeks to figure out, edit, and I tested it ingame around 50+ times. Besides, I'm working on my own crazy game, and I'm really sorry I cant help any more. :) |
|
|
| Report Abuse |
|
|
MattJon
|
  |
| Joined: 28 Apr 2009 |
| Total Posts: 660 |
|
| |
|
MattJon
|
  |
| Joined: 28 Apr 2009 |
| Total Posts: 660 |
|
|
| 07 Apr 2013 09:26 PM |
| Nevermind... Me, being the idiot I am, never switched SaveNumber and LoadNumber to SaveString and LoadString |
|
|
| Report Abuse |
|
|
FoggedOut
|
  |
| Joined: 09 Dec 2011 |
| Total Posts: 3021 |
|
|
| 07 Apr 2013 10:34 PM |
| Haha, never thought it would be that easy. xD |
|
|
| Report Abuse |
|
|