generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: DATA Save

Previous Thread :: Next Thread 
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
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
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
16 Jul 2011 10:22 AM
50 views, no help.

:l
Report Abuse
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
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
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
16 Jul 2011 10:25 AM
So sorry, the first argument wasn't required.

p:SaveLeaderboardData()
Report Abuse
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
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
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
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
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
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
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
16 Jul 2011 10:30 AM
That's not a script error. That's a studio error.
Report Abuse
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
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
MARIOSTAR6464 is not online. MARIOSTAR6464
Joined: 21 Jul 2008
Total Posts: 13674
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
SoulStealer9875 is not online. SoulStealer9875
Joined: 20 Jul 2009
Total Posts: 13119
16 Jul 2011 10:46 AM
Good to know.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image