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: Is this how to use Data Persistance?

Previous Thread :: Next Thread 
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
07 Aug 2012 08:19 PM
game.Players.PlayerAdded:connect(function(player)
repeat wait() until player.Character and player.PlayerGui
player:WaitForDataReady()
m = Instance.new("IntValue", player)
m.Name = "leaderstats"

h = Instance.new("IntValue", m)
h.Name = "Stage"
n.Value = 1

player.leaderstats.Stage:LoadNumber("Stage")

end)

game.Players.PlayerRemoving:connect(function(REMplayer)
REMplayer.leaderstats.Stage:SaveNumber("Stage")
end)

help?!?!
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
07 Aug 2012 08:22 PM
ha;!
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
07 Aug 2012 08:23 PM
@NONE?
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
07 Aug 2012 08:26 PM
CMON
Report Abuse
Woodstauk4 is not online. Woodstauk4
Joined: 27 Dec 2010
Total Posts: 3061
07 Aug 2012 08:32 PM
I'm afraid your a bit off.

(player):SaveNumber("name of value",value itself)
(player):LoadNumber("name of value")


fixed script:


game.Players.PlayerAdded:connect(function(player)
player:WaitForDataReady()
m = Instance.new("IntValue", player)
m.Name = "leaderstats"
h = Instance.new("IntValue", m)
h.Name = "Stage"
h.Value=player:LoadNumber("Stage")>1 and player:LoadNumber("Stage")or 1
end)
coroutine.resume(coroutine.create(function()
game.Players.PlayerRemoving:connect(function(REMplayer)
REMplayer:SaveNumber("Stage",REMplayer.leaderstats.Stage.Value)
end)
end))
Report Abuse
Woodstauk4 is not online. Woodstauk4
Joined: 27 Dec 2010
Total Posts: 3061
07 Aug 2012 08:33 PM
Sorry I'll further explain :SaveNumber,
(player):SaveNumber("name of value",Value of the IntValue, otherwise you'd be saving an instance. So this saves the number, not the entire leaderstats)
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
07 Aug 2012 08:38 PM
Does that script still set the Value to 1 when they're new players?
Report Abuse
Woodstauk4 is not online. Woodstauk4
Joined: 27 Dec 2010
Total Posts: 3061
07 Aug 2012 08:39 PM
Yes.
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
07 Aug 2012 08:40 PM
That script doesn't even insert the leaderstats and Stages.
Report Abuse
Woodstauk4 is not online. Woodstauk4
Joined: 27 Dec 2010
Total Posts: 3061
07 Aug 2012 08:44 PM
Are you saying that because it didn't work right online?


I'll cut out the ternary operator for a nooby inefficient thingamajig if it wasn't working in game..


game.Players.PlayerAdded:connect(function(player)
player:WaitForDataReady()
m = Instance.new("IntValue", player)
m.Name = "leaderstats"
h = Instance.new("IntValue", m)
h.Name = "Stage"
if player:LoadNumber("Stage")and player:LoadNumber("Stage")>1 then
h.Value=player:LoadNumber("Stage")
else
h.Value=1
end
end)
coroutine.resume(coroutine.create(function()
game.Players.PlayerRemoving:connect(function(REMplayer)
REMplayer:SaveNumber("Stage",REMplayer.leaderstats.Stage.Value)
end)
end))
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
07 Aug 2012 08:46 PM
It doesn't work in both offline and online mode.
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
07 Aug 2012 08:52 PM
And there are no errors.
Report Abuse
Woodstauk4 is not online. Woodstauk4
Joined: 27 Dec 2010
Total Posts: 3061
07 Aug 2012 08:54 PM
game:GetService("Players")PlayerAdded:connect(function(p)
ypcall(function()
p:WaitForDataReady()
local m=Instance.new("IntValue",p)
m.Name="leaderstats"
local h=Instance.new("IntValue",m)
h.Name="Stage"
h.Value=p:LoadNumber("Stage")>1 and p:LoadNumber("Stage")or 1
end)
end)
coroutine.resume(coroutine.create(function()
game:GetService("Players").PlayerRemoving:connect(function(r)
r:SaveNumber("Stage",r:FindFirstChild("leaderstats"):FindFirstChild("Stage").Value)
end)
end))











All of the scripts I've given you should work, if this still doesn't then... well either you're doing something wrong or I'm more tired than I think.
Report Abuse
Woodstauk4 is not online. Woodstauk4
Joined: 27 Dec 2010
Total Posts: 3061
07 Aug 2012 08:55 PM
Oops.


game:GetService("Players")PlayerAdded:connect(function(p)
ypcall(function()
p:WaitForDataReady()
local m=Instance.new("IntValue",p)
m.Name="leaderstats"
local h=Instance.new("IntValue",m)
h.Name="Stage"
h.Value=p:LoadNumber("Stage")>1 and p:LoadNumber("Stage")or 1
end)
end)
coroutine.resume(coroutine.create(function()
game:GetService("Players").PlayerRemoving:connect(function(r)
r:SaveNumber("Stage",r:FindFirstChild("leaderstats"):FindFirstChild("Stage").Value)
end)
end))


Also, you can't be in offline or play solo or any of those, data persistence strictly works in Play mode only
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
07 Aug 2012 09:15 PM
Thanks, that worked!
Report Abuse
thedeathmaster01 is not online. thedeathmaster01
Joined: 14 Mar 2010
Total Posts: 6331
17 Aug 2012 01:04 AM
2995...

~2.9k posts/20k posts
Report Abuse
sonicdiablo is not online. sonicdiablo
Joined: 05 Feb 2009
Total Posts: 1661
17 Aug 2012 01:39 AM
It doesn't work.Why?Because You can't save when a player leave.Use another event to trigger it.
Report Abuse
Woodstauk4 is not online. Woodstauk4
Joined: 27 Dec 2010
Total Posts: 3061
17 Aug 2012 01:50 AM
game:GetService("Players")PlayerAdded:connect(function(p)
ypcall(function()
p:WaitForDataReady()
local m=Instance.new("IntValue",p)
m.Name="leaderstats"
local h=Instance.new("IntValue",m)
h.Name="Stage"
h.Value=p:LoadNumber("Stage")>1 and p:LoadNumber("Stage")or 1
end)
coroutine.resume(coroutine.create(function()
h.Changed:connect(function()
p:SaveNumber("Stage",h.Value)
end)
end))
end)
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