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 persistence in leaderboard not working

Previous Thread :: Next Thread 
Nexun is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. 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 is not online. LordPixel
Joined: 10 Feb 2010
Total Posts: 526
06 Aug 2011 08:19 PM
you don't need to GetService players.
Report Abuse
Nexun is not online. Nexun
Joined: 04 Aug 2011
Total Posts: 371
06 Aug 2011 10:46 PM
So? It works, with or without it.
Report Abuse
Nexun is not online. 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 is not online. Nexun
Joined: 04 Aug 2011
Total Posts: 371
08 Aug 2011 03:47 PM
Anyone at all?
Report Abuse
Nexun is not online. 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
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