A Roblox Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeLatest imagesRegisterLog in
If you're a experienced coder make some tutorials! It would really help the site grow.
Make sure you read the rules(Which can be found by clicking here)
If you're a beginner at coding, try some tutorials.
We have many Moderators/Admins watching this site. Contact them with Questions.
Let us know what your favorite sport is. By clicking here to vote (Click here)
This site is becoming inactive. Lets make it active.
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
Top posters
blueymaddog
Data Persistence Explained Vote_lcapData Persistence Explained Voting_barData Persistence Explained Vote_rcap 
naknak
Data Persistence Explained Vote_lcapData Persistence Explained Voting_barData Persistence Explained Vote_rcap 
Supernapalm
Data Persistence Explained Vote_lcapData Persistence Explained Voting_barData Persistence Explained Vote_rcap 
m27frogy
Data Persistence Explained Vote_lcapData Persistence Explained Voting_barData Persistence Explained Vote_rcap 
slayer9365
Data Persistence Explained Vote_lcapData Persistence Explained Voting_barData Persistence Explained Vote_rcap 
myrco919
Data Persistence Explained Vote_lcapData Persistence Explained Voting_barData Persistence Explained Vote_rcap 
branefreez
Data Persistence Explained Vote_lcapData Persistence Explained Voting_barData Persistence Explained Vote_rcap 
ninga95
Data Persistence Explained Vote_lcapData Persistence Explained Voting_barData Persistence Explained Vote_rcap 
CloneTrooper787
Data Persistence Explained Vote_lcapData Persistence Explained Voting_barData Persistence Explained Vote_rcap 
raboy117
Data Persistence Explained Vote_lcapData Persistence Explained Voting_barData Persistence Explained Vote_rcap 
Top posting users this month
No user
Latest topics
» Where to go from here.
Data Persistence Explained EmptySeptember 14th 2020, 1:20 pm by MrNicNac

» Send me an Email
Data Persistence Explained EmptySeptember 14th 2020, 1:16 pm by MrNicNac

» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]
Data Persistence Explained EmptyJuly 6th 2015, 7:38 pm by m27frogy

» New Site Possibly
Data Persistence Explained EmptyJuly 6th 2015, 4:16 pm by m27frogy

» Ambassador!
Data Persistence Explained EmptyApril 15th 2015, 11:40 pm by naknak

» Boop - Tag
Data Persistence Explained EmptyApril 13th 2015, 9:46 pm by naknak

» Vip Class Script
Data Persistence Explained EmptyApril 13th 2015, 4:54 pm by naknak

» Who's active?!
Data Persistence Explained EmptyApril 13th 2015, 4:52 pm by naknak

» Genesis Point
Data Persistence Explained EmptyJuly 17th 2014, 7:04 pm by branefreez

» Reward System
Data Persistence Explained EmptyJuly 17th 2014, 5:41 am by m27frogy

» Script Request
Data Persistence Explained EmptyJuly 10th 2014, 11:43 am by naknak

» local scripts?
Data Persistence Explained EmptyJuly 10th 2014, 11:39 am by naknak

» Project: Reconstruction [Died]
Data Persistence Explained EmptyJuly 10th 2014, 11:36 am by naknak

» Hi. I am new here
Data Persistence Explained EmptyApril 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
Data Persistence Explained EmptyJanuary 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
Data Persistence Explained EmptyJanuary 1st 2014, 2:11 pm by m27frogy

» Gun Making! [READ DESC]
Data Persistence Explained EmptyJanuary 1st 2014, 2:10 pm by m27frogy

» Hi, I am new here!
Data Persistence Explained EmptyNovember 26th 2013, 3:33 pm by Keanu73

» Improve Coding
Data Persistence Explained EmptyOctober 26th 2013, 1:12 pm by pook03

» Simple Button
Data Persistence Explained EmptySeptember 1st 2013, 6:19 pm by branefreez


 

 Data Persistence Explained

Go down 
4 posters
AuthorMessage
m27frogy
The Garbageman
m27frogy


Posts : 336
Join date : 2011-06-23

Data Persistence Explained Empty
PostSubject: Data Persistence Explained   Data Persistence Explained EmptyJune 24th 2011, 10:41 am

Important modules (called functions by some) you need to know:

Player:WaitForDataReady()
pcall(function() end)
Player:SaveBoolean(String key, Boolean value)
Player:SaveString(String key, String value)
Player:SaveNumber(String key, Number value)
Player:SaveInstace(String key, Instance value)
Player:LoadBoolean(String key)
Player:LoadString(String key)
Player:LoadNumber(String key)
Player:LoadInstace(String key)

What's all this about LoadInstances, WaitForDataReady, pcalls? Okay, I'll try to explain it. I'll start with the basics. A Player can recieve data that can be recalled later (even on a different server, although not on a different game) using a Load. To save data, first you need to get to the Player you want to save to. Then you use the appropriate Save function to save your data. Then replace String key with the name under which the data will be saved. Remember, this is a string value, so it needs "" even if its a name made up of numbers. Next, replace the other value with the type of data your saving. Let's say you're trying to save a true or false statement under the name "Bool". This is how it should look:
Code:
player = game.Players:FindFirstChild("m27frogy")
player:SaveBoolean("Bool", true)
Technically speaking, this previous code would not work, so don't try. First, when the game first starts, "player" won't be ready to save data yet. That's where WaitForDataReady comes in. This waits until the player is ready before it continues the script. Usually soon after a player gets into the game, he's ready to recieve data. So here's our new script:
Code:
player = game.Players:FindFirstChild("m27frogy")
player:WaitForDataReady()
player:SaveBoolean("Bool", true)
So is the script ready yet? Not quite. There's still a problem. What if for some reason, the Save didn't work? The script would crash, right? What we need is a way to decide if the code executed or not, then display a error message if it didn't... The answer is pcall! pcall is a protected call, it's also the only way a Save or Load will run. You could just say pcall(function() player:SaveBoolean("Bool", true) end), but that isn't very effective. It still has no way of telling the user a problem occured until it's too late. Why not use a if not pcall() then end? This says basically, if I can't do this pcall, then do this. Using this knowledge, I'd use this script:
Code:
player = game.Players:FindFirstChild("m27frogy")
player:WaitForDataReady()
if not pcall(function() player:SaveBoolean("Bool", true) end) then
  print("Oopsy, the save made a mistake.")
end
Great, the script works now, right? Wait a moment, there's no way of retrieving the data! Load works the same as save except you need to know only the string name and it returns something. The best way to use it is to declare it as a variable. The final code will show you what I mean:
Code:
player = game.Players:FindFirstChild("m27frogy")
player:WaitForDataReady()
if not pcall(function() player:SaveBoolean("Bool", true) end) then
  print("Oopsy, the save made a mistake.")
end
if not pcall(function() bool = player:LoadBoolean("Bool") end) then
  bool = false
  print("The 'Bool' value doesn't exist!  Defaulting!")
end
print(bool)


For Advanced Scripters:
I've used these techniques to build a saving text editor. I hope ROBLOX's next invention will be saving to the game, not just to players.
Back to top Go down
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

Data Persistence Explained Empty
PostSubject: Re: Data Persistence Explained   Data Persistence Explained EmptyJune 24th 2011, 11:56 am

They really should allow saving to the game. It would open many doors that I'd like open.
Back to top Go down
m27frogy
The Garbageman
m27frogy


Posts : 336
Join date : 2011-06-23

Data Persistence Explained Empty
PostSubject: Re: Data Persistence Explained   Data Persistence Explained EmptyJune 24th 2011, 2:07 pm

I'd agree. I'd suppose the only option is a dedicated user for saving that rejoins the server every 40 minutes.... Did you check my Building Intermediate Tutorial: NXT Building?
Back to top Go down
m27frogy
The Garbageman
m27frogy


Posts : 336
Join date : 2011-06-23

Data Persistence Explained Empty
PostSubject: Re: Data Persistence Explained   Data Persistence Explained EmptyJune 24th 2011, 2:14 pm

Wait a minute, sudden lightbulb, they don't because of VIRUSES!!!
Back to top Go down
Supernapalm
Expert Scripter
Expert Scripter
avatar


Posts : 393
Join date : 2011-01-17

Data Persistence Explained Empty
PostSubject: Re: Data Persistence Explained   Data Persistence Explained EmptyJune 24th 2011, 9:19 pm

duuuh. XD
Back to top Go down
http://hackthissite.org
m27frogy
The Garbageman
m27frogy


Posts : 336
Join date : 2011-06-23

Data Persistence Explained Empty
PostSubject: Re: Data Persistence Explained   Data Persistence Explained EmptyJune 25th 2011, 7:51 pm

Thanks for pointing out my stupidity...
Back to top Go down
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

Data Persistence Explained Empty
PostSubject: Re: Data Persistence Explained   Data Persistence Explained EmptyJune 28th 2011, 10:07 am

That's why the owner should get an anti virus if he really cares.
Back to top Go down
blueymaddog
Administrator
Administrator
blueymaddog


Posts : 1081
Join date : 2010-12-09
Age : 26

Data Persistence Explained Empty
PostSubject: Re: Data Persistence Explained   Data Persistence Explained EmptyFebruary 4th 2012, 8:10 am

or they should just remove free models entirely...
Back to top Go down
Sponsored content





Data Persistence Explained Empty
PostSubject: Re: Data Persistence Explained   Data Persistence Explained Empty

Back to top Go down
 
Data Persistence Explained
Back to top 
Page 1 of 1
 Similar topics
-
» Data Persistence Tutorial [ Numbers Saving ]

Permissions in this forum:You cannot reply to topics in this forum
A Roblox Community :: Tutorials and Resources :: Advanced-
Jump to: