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 Problem.

Previous Thread :: Next Thread 
Spectrumz is not online. Spectrumz
Joined: 22 Mar 2011
Total Posts: 4338
30 Jul 2011 02:06 PM
game.Players.PlayerAdded:connect(function(p)
local leaderstats = Instance.new("IntValue", p)
leaderstats.Name = "leaderstats"
local GP = Instance.new("IntValue", leaderstats)
GP.Name = "GP"
p:WaitForDataReady()
local gold = p:LoadNumber("Gold")
GP.Value = gold
end)

game.Players.PlayerRemoving:connect(function(player)
player:WaitForDataReady()
local stats = player:findFirstChild("leaderstats")
if stats then
local pieces = stats:findFirstChild("GP")
if pieces then
player:SaveNumber("Gold", pieces.Value)
end
end
end)

I'm only posting this thread again because I was on vacation for a week and I lost my previous thread. Now, my problem is that this doesn't save/load anything. I even added a brick that when touched will give you some GP. What I did to test this is touch the brick a few times until I had maybe 10 GP, and left. I then went back in and had 0 GP. The output says nothing. Help?
Report Abuse
chikenugget is not online. chikenugget
Joined: 09 May 2009
Total Posts: 2552
30 Jul 2011 02:09 PM
I hope this helps...


game.Players.PlayerAdded:connect(function(p)
local leaderstats = Instance.new("IntValue", p)
leaderstats.Name = "leaderstats"
local GP = Instance.new("IntValue", leaderstats)
GP.Name = "GP"
p:WaitForDataReady()
local gold = p:LoadNumber(p.Name)
GP.Value = gold
end)

game.Players.PlayerRemoving:connect(function(player)
player:WaitForDataReady()
local stats = player:findFirstChild("leaderstats")
if stats then
local pieces = stats:findFirstChild("GP")
if pieces then
pieces:SaveNumber(player.Name, pieces.Value)
end
end
end)
Report Abuse
61352151511 is not online. 61352151511
Joined: 30 Nov 2009
Total Posts: 8094
30 Jul 2011 02:15 PM
game.Players.PlayerAdded:connect(function(p)
p:WaitForDataReady()
leaderstats, GP = Instance.new("IntValue", p), Instance.new("IntValue", leaderstats)
leaderstats.Name, GP.Name = "leaderstats", "GP"
GP.Value = p:LoadNumber("Gold")
end)

game.Players.PlayerRemoving:connect(function(player)
player:WaitForDataReady()
if player:FindFirstChild("leaderstats") then
if stats:FindFirstChild("GP") then
player:SaveNumber("Gold", stats:FindFirstChild("GP").Value)
end
end
end)

~ A Signature
Report Abuse
Spectrumz is not online. Spectrumz
Joined: 22 Mar 2011
Total Posts: 4338
30 Jul 2011 03:35 PM
@Mitch

Nope.
Report Abuse
chikenugget is not online. chikenugget
Joined: 09 May 2009
Total Posts: 2552
30 Jul 2011 03:36 PM
I bet you didn't even try mine >_<
Report Abuse
eXoguti093 is not online. eXoguti093
Joined: 17 Oct 2008
Total Posts: 1786
30 Jul 2011 04:33 PM
Use ChildAdded and ChildRemoved, they are never gonna fix the PlayerAdded thing, it does't work the first time because you are already in the server when the script runs or something like that, bu ChildAdded works.
Report Abuse
TwilightKnights is not online. TwilightKnights
Joined: 12 Apr 2009
Total Posts: 2680
30 Jul 2011 04:37 PM
@Mitch


That wouldn't work. The IntValue that is tagged as GP would be made "at the same time" as the other one, therfore it would say leaderstats is a nil valure.
Report Abuse
Spectrumz is not online. Spectrumz
Joined: 22 Mar 2011
Total Posts: 4338
30 Jul 2011 06:47 PM
@eXoguti

Uh huh. Then why does my leaderboard actually insert the leaderstats and GP IntValues, and they're visible on the in-game leaderboard?
Report Abuse
61352151511 is not online. 61352151511
Joined: 30 Nov 2009
Total Posts: 8094
30 Jul 2011 06:57 PM
@Twil, I found that out after I wrote the script, after trying to make efficient stuff it makes it not as efficient

~ A Signature
Report Abuse
Darknesschaos is not online. Darknesschaos
Joined: 11 May 2009
Total Posts: 6154
30 Jul 2011 07:16 PM
Cool.
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