|
| 16 Jul 2011 10:04 AM |
I have a script, it works a lot of the time, but at times it can malfunction. I was wondering what I'm missing out of my script. Could it possibly be that I just need a wait() at the start of functions to give the computer a chance if 2 people join at the same time?
game.Players.PlayerRemoving:connect(function(p) if p:findFirstChild("leaderstats") then p:SaveInstance("SavedStatPNum"..tostring(game.PlaceId),p.leaderstats) end end) game.Players.PlayerAdded:connect(function(p)
repeat wait() until p:findFirstChild("leaderstats") p:WaitForDataReady()
local Loaded = nil if p:findFirstChild("leaderstats") and #p:LoadInstance("SavedStatPNum"..tostring(game.PlaceId)):GetChildren()>0 then Loaded = p:LoadInstance("SavedStatPNum"..tostring(game.PlaceId)) for j, v in pairs(Loaded:GetChildren()) do pcall(function() p.leaderstats[v.Name].Value = v.Value end) end end end) |
|
|
| Report Abuse |
|
|
| |
|
|
| 16 Jul 2011 10:24 AM |
"p:SaveInstance("SavedStatPNum"..tostring(game.PlaceId),p.leaderstats)"
Why did you need to make the key so long? All you really needed to do was something simple.
Try this,
p:SaveLeaderboardData("SavedStatPNum") |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2011 10:25 AM |
So sorry, the first argument wasn't required.
p:SaveLeaderboardData() |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2011 10:26 AM |
| Ah thanks bud, I knew something like that existed but I couldn't find in the object browser. |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2011 10:28 AM |
It comes under Player in the object browser.
You can get the full list of arguments and details from that. |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2011 10:29 AM |
Do I do the same thing with the load part, using LoadLeaderboardData()?
When I pasted my script into workspace the output read (without me pressing play)
Sat Jul 16 16:28:02 2011 - Unknown object class "Workspace" while reading XML
|
|
|
| Report Abuse |
|
|
|
| 16 Jul 2011 10:30 AM |
| That's not a script error. That's a studio error. |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2011 10:37 AM |
If that doesn't work, I've already re-written your script
game.Players.PlayerRemoving:connect(function(p) p:SaveLeaderboardData() end)
game.Players.PlayerAdded:connect(function(p) p:WaitForDataReady() local Loaded = nil p:LoadLeaderboardData() for _,v in pairs(p.leaderstats:children()) do pcall(function() p.leaderstats[v.Name].Value = v.Value end) end end) |
|
|
| Report Abuse |
|
|
|
| 16 Jul 2011 10:41 AM |
I think if looks aye okay.
game.Players.PlayerRemoving:connect(function(p) if p:findFirstChild("leaderstats") then p:SaveLeaderboardData() end end) game.Players.PlayerAdded:connect(function(p)
repeat wait() until p:findFirstChild("leaderstats") p:WaitForDataReady()
local Loaded = nil if p:findFirstChild("leaderstats") and #p:LoadLeaderboardData():GetChildren()>0 then Loaded = p:LoadLeaderboardData() for j, v in pairs(Loaded:GetChildren()) do pcall(function() p.leaderstats[v.Name].Value = v.Value end) end end end) |
|
|
| Report Abuse |
|
|
| |
|