Nexun
|
  |
| Joined: 04 Aug 2011 |
| Total Posts: 371 |
|
|
| 05 Aug 2011 09:55 PM |
game:GetService("Players").PlayerAdded:connect(function(p) p:WaitForDataReady() local stats = Instance.new("IntValue", p) stats.Name = "leaderstats" local gold = Instance.new("IntValue", stats) gold.Name = "GP" if pcall(function() local gold_pieces = p:LoadNUmber("Gold") end) then gold.Value = gold_pieces end end)
game:GetService("Players").PlayerRemoving:connect(function(player) player:WaitForDataReady() local stats = player:findFirstChild("leaderstats") if stats then local gold = stats:findFirstChild("GP") if gold then if pcall(function() player:SaveNumber("Gold", gold.Value) end) then end end end end)
There's no output for this script, and I use pcall() for both saving and loading the number. |
|
|
| Report Abuse |
|
|
pwnedu46
|
  |
| Joined: 23 May 2009 |
| Total Posts: 7534 |
|
|
| 05 Aug 2011 10:44 PM |
Pcall stands for protected call; it is only in case your script crashes for some reason. It isn't as necessary anymore because the DP system is more stable now, but still a good practice. Personally, I save every time it changes as opposed to when the player leaves.
______________________________________ ~pwnedu46~ -I lost the game.-
|
|
|
| Report Abuse |
|
|
Spectrumw
|
  |
| Joined: 04 Aug 2009 |
| Total Posts: 13510 |
|
|
| 05 Aug 2011 10:45 PM |
"p:LoadNUmber("Gold")"
Isn't it supposed to be LoadNumber()? |
|
|
| Report Abuse |
|
|
Nexun
|
  |
| Joined: 04 Aug 2011 |
| Total Posts: 371 |
|
|
| 06 Aug 2011 04:34 PM |
@pwnedu
I find it to be more efficient than having to create a few extra lines of code.
@Spectrumw
Thanks, I'll see what happens when I fix it. |
|
|
| Report Abuse |
|
|
Nexun
|
  |
| Joined: 04 Aug 2011 |
| Total Posts: 371 |
|
|
| 06 Aug 2011 04:39 PM |
Still no results, even with the updated version.
game:GetService("Players").PlayerAdded:connect(function(p) p:WaitForDataReady() local stats = Instance.new("IntValue", p) stats.Name = "leaderstats" local gold = Instance.new("IntValue", stats) gold.Name = "GP" if pcall(function() local gold_pieces = p:LoadNumber("Gold") end) then gold.Value = gold_pieces end end)
game:GetService("Players").PlayerRemoving:connect(function(player) player:WaitForDataReady() local stats = player:findFirstChild("leaderstats") if stats then local gold = stats:findFirstChild("GP") if gold then if pcall(function() player:SaveNumber("Gold", gold.Value) end) then end end end end) |
|
|
| Report Abuse |
|
|
Nexun
|
  |
| Joined: 04 Aug 2011 |
| Total Posts: 371 |
|
|
| 06 Aug 2011 04:59 PM |
@pwnedu46
I might try out your method if mine ends up not working for some reason. Is this similar to what you use?
script.Parent.Changed:connect(function(property) if property == "Value" then --[[Variable you somehow got the player with--]]:SaveNumber("Number", property) end end) |
|
|
| Report Abuse |
|
|
Nexun
|
  |
| Joined: 04 Aug 2011 |
| Total Posts: 371 |
|
|
| 06 Aug 2011 08:06 PM |
I tried your way, pwnedu46, no dice.
Anyone else have an answer? |
|
|
| Report Abuse |
|
|
LordPixel
|
  |
| Joined: 10 Feb 2010 |
| Total Posts: 526 |
|
|
| 06 Aug 2011 08:19 PM |
| you don't need to GetService players. |
|
|
| Report Abuse |
|
|
Nexun
|
  |
| Joined: 04 Aug 2011 |
| Total Posts: 371 |
|
|
| 06 Aug 2011 10:46 PM |
| So? It works, with or without it. |
|
|
| Report Abuse |
|
|
Nexun
|
  |
| Joined: 04 Aug 2011 |
| Total Posts: 371 |
|
|
| 07 Aug 2011 11:07 PM |
| Does ANYONE have an answer to my question? |
|
|
| Report Abuse |
|
|
Nexun
|
  |
| Joined: 04 Aug 2011 |
| Total Posts: 371 |
|
| |
|
Nexun
|
  |
| Joined: 04 Aug 2011 |
| Total Posts: 371 |
|
|
| 08 Aug 2011 07:43 PM |
| Would it possibly be because I am using local variables that have already been recycled? |
|
|
| Report Abuse |
|
|