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
 

Data Persistence help

Previous Thread :: Next Thread 
kingmod123 is not online. kingmod123
Joined: 16 May 2009
Total Posts: 699
17 Sep 2011 07:01 PM
Anyone know why this doesn't work? No output, sorry.

game.Players.PlayerRemoving:connect(function(oldP)
oldP:WaitForDataReady()
ls = oldP:findFirstChild("leaderstats")
if ls then
mon = ls:findFirstChild("Money")
if mon then
oldP:SaveNumber("Money", mon.Value)
end
end
end)

game.Players.PlayerAdded:connect(function(newP)
newP:WaitForDataReady()
local leaderstats = Instance.new("Model", newP)
leaderstats.Name = "leaderstats"

local money = Instance.new("IntValue", leaderstats)
money.Name = "Money"

while true do
wait(3)
money.Value = money.Value + 10
end

SavedMoney = newP:LoadNumber("Money")
if SavedMoney.Value == 0 then
SavedMoney.Value = 1
end

mon.Value = SavedLevel
end)
Report Abuse
kingmod123 is not online. kingmod123
Joined: 16 May 2009
Total Posts: 699
17 Sep 2011 07:32 PM
Bump
Report Abuse
GoldenUrg is not online. GoldenUrg
Joined: 23 Aug 2009
Total Posts: 6428
17 Sep 2011 07:58 PM
Doing a wait in PlayerRemoving event is dangerous, the player may be gone before the wait finishes.

You should add a method to save the data manually, so you can test whether it's save or load that is failing.
Report Abuse
jjjakey is not online. jjjakey
Joined: 15 Sep 2008
Total Posts: 13014
17 Sep 2011 08:11 PM
Actually, PlayerRemoving is better for Data Persistence. This is because the data isn't sent to the Roblox server until the player leaves.

Anyways, you'll want to remove the 'WaitForDataReady()' in the PlayerRemoving function. You want to capture the data your going to save as soon as possible.
Report Abuse
kingmod123 is not online. kingmod123
Joined: 16 May 2009
Total Posts: 699
17 Sep 2011 08:24 PM
Ok, thanks ;)
Report Abuse
jjjakey is not online. jjjakey
Joined: 15 Sep 2008
Total Posts: 13014
17 Sep 2011 08:26 PM
If your STILL having troubles, try to make a string of whatever your going to save. That way, you got your data and the player can leave.

game.Players.PlayerRemoved:connect(function(Player)
Number = Player.leaderstats.Number.Value

Then you can save the number from there.
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