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

Previous Thread :: Next Thread 
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 02:16 PM
Can someone help fix this?

function savescore()
player = script.Parent.Parent.Parent.Parent
player:WaitForDataReady()
stats = player:FindFirstChild("leaderstats")
speedx = player:findFirstChild("Speed")
healthx = player:findFirstChild("Health")
levels = stats:FindFirstChild("Level")
xps = stats:findFirstChild("XP")
golds = stats:findFirstChilld("Gold")
player:SaveNumber("level",levels.Value)
player:SaveNumber("xp", xps.Value)
player:SaveNumber("gold", golds.Value)
player:SaveNumber("speed", speedx.Value)
player:SaveNumber("health", healthx.Value)
if game.Lighting:findFirstChild("GUI"..player.Name.."GUI") then
player:SaveInstance("Shop",game.Lighting:findFirstChild("GUI"..player.Name.."GUI"))
end
m = Instance.new("Message",player.PlayerGui)
m.Text = "Game Saved!"
game.Debris:AddItem(m,2)
end
Report Abuse
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 02:18 PM
idk what the error is because you can't use data persistence in edit mode
Report Abuse
TheMyrco is not online. TheMyrco
Joined: 13 Aug 2011
Total Posts: 15105
26 Nov 2011 02:19 PM
You never called the function...

~Myrco; Music lover, nederlands/dutch and a scripter
Report Abuse
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 02:20 PM
Yes I did in the script it is called from when the TextButton is clicked.
Report Abuse
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 02:20 PM
script.Parent.Save.MouseButton1Click:connect(savescore)
Report Abuse
TheMyrco is not online. TheMyrco
Joined: 13 Aug 2011
Total Posts: 15105
26 Nov 2011 02:28 PM
And both codes are in the same script, right?

(I'm too lazy to read it trough,, because I'm currently foruming in Scripters and soon going to do something else).

~Myrco; Music lover, nederlands/dutch and a scripter
Report Abuse
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 02:28 PM
Yes they are.
Report Abuse
ReactorINC is not online. ReactorINC
Joined: 24 Nov 2011
Total Posts: 84
26 Nov 2011 02:29 PM
DataPersistence doesn't work on Edit mode. (WaitForDataReady will wait forever)

I'm sorry but you will have to test it online.
Report Abuse
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 02:43 PM
No duh! That's what I'm asking for. I tested it and it won't work.
Report Abuse
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 03:09 PM
Bump
Report Abuse
theblob5743 is not online. theblob5743
Joined: 08 Nov 2008
Total Posts: 1574
26 Nov 2011 03:15 PM
It looks fine to me. Post your data loading function also.
Report Abuse
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 03:18 PM
I know the save one doesn't work because the message doesn't come up but I'll post the whole script...
Report Abuse
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 03:20 PM
function savescore()
player = script.Parent.Parent.Parent.Parent
player:WaitForDataReady()
stats = player:FindFirstChild("leaderstats")
speedx = player:findFirstChild("Speed")
healthx = player:findFirstChild("Health")
levels = stats:FindFirstChild("Level")
xps = stats:findFirstChild("XP")
golds = stats:findFirstChilld("Gold")
player:SaveNumber("level",levels.Value)
player:SaveNumber("xp", xps.Value)
player:SaveNumber("gold", golds.Value)
player:SaveNumber("speed", speedx.Value)
player:SaveNumber("health", healthx.Value)
if game.Lighting:findFirstChild("GUI"..player.Name.."GUI") then
player:SaveInstance("Shop",game.Lighting:findFirstChild("GUI"..player.Name.."GUI"))
end
m = Instance.new("Message",player.PlayerGui)
m.Text = "Game Saved!"
game.Debris:AddItem(m,2)
end

function loadscore()
player = script.Parent.Parent.Parent.Parent
if player.Loaded.Value == false then
player.Loaded.Value = true
player:WaitForDataReady()
local level = player:LoadNumber("level")
if level ~= 0 then
player.leaderstats.Level.Value = level
end
local xp = player:LoadNumber("xp")
if xp ~= 0 then
player.leaderstats.XP.Value = xp
end
local money = player:LoadNumber("gold")
if money ~= 0 then
player.leaderstats.Gold.Value = money
end
local speed = player:LoadNumber("speed")
if speed ~= 0 then
player.Speed.Value = speed
end
local health = player:LoadNumber("health")
if health ~= 0 then
player.Health.Value = health
end
gui = player:LoadInstance("Shop")
gui.Parent = player.PlayerGui
gui:clone().Parent = game.Lighting
m = Instance.new("Message",player.PlayerGui)
m.Text = "Game Loaded"
game.Debris:AddItem(m,2)
end end

script.Parent.Load.MouseButton1Click:connect(loadscore)
script.Parent.Save.MouseButton1Click:connect(savescore)
Report Abuse
theblob5743 is not online. theblob5743
Joined: 08 Nov 2008
Total Posts: 1574
26 Nov 2011 03:22 PM
Are "Save" and "Load" parts or clickdetectors?
Report Abuse
ReactorINC is not online. ReactorINC
Joined: 24 Nov 2011
Total Posts: 84
26 Nov 2011 03:27 PM
WaitForDataReady will wait forever on edit or play solo.

Just incase you are testing it on that.
Report Abuse
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 03:30 PM
reactor I'm not and it is a gui
Report Abuse
TheImpersonator is not online. TheImpersonator
Joined: 19 Jul 2011
Total Posts: 111
26 Nov 2011 03:30 PM
Have you put it in a localscript or normal script?
Report Abuse
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 03:33 PM
normal
Report Abuse
sncplay42 is not online. sncplay42
Joined: 27 Nov 2008
Total Posts: 11891
26 Nov 2011 05:06 PM
What adds the leaderstats and when?
Report Abuse
br45entei is not online. br45entei
Joined: 06 Nov 2010
Total Posts: 1058
26 Nov 2011 05:13 PM
in the pcall section, make it output to a message in your player.Playergui, that way you can see the output in-game.
Report Abuse
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 05:42 PM
I figured it out!! I added an extra l where it says findFirstChild("Gold")

I said findFirstChilld("Gold") -_-
Report Abuse
nPwn is not online. nPwn
Joined: 17 Sep 2010
Total Posts: 3197
26 Nov 2011 05:42 PM
@br45 I totally did that to figure it out before I saw you say that XD
Report Abuse
br45entei is not online. br45entei
Joined: 06 Nov 2010
Total Posts: 1058
27 Nov 2011 04:58 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