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 » Scripters
Home Search
 

Guide to Data Stores

Previous Thread :: Next Thread 
Lecturous is not online. Lecturous
Joined: 17 Aug 2013
Total Posts: 1096
18 Mar 2015 01:35 PM
Alright, DO NOT USE DATA PERSISTENCE ANYMORE. For now on: Use Data Stores.
Wiki page: http://wiki.roblox.com/index.php?title=Data_store

Basically, I'll give you a mini lesson.
You get the service by inputting this line at the beginning of your script / before where you first use it.
local ds = game:GetService("DataStoreService"):GetDataStore([input a random string here, because this is a variable.])

There are methods to saving stuff using DataStores. You can save any value, but not "ROBLOX types like Vector3, Instance, or Part." The methods are here:

ds:SetAsync(key, value)
Data Stores save values like tables (in the way that each save has a key and a value.) To access each save and the value to a save, you need to first make the save actually EXIST. That's what this function is for, making new saves in DataStores. You need to make a key for the data stores, a key that can be accessed from any other part of your script (or at least, that's how I've been doing it) and a value that can be accessed from your key. Also, did I mention that keys need to be strings? For example:

local ds = game:GetService("DataStoreService"):GetDataStore(game.Name) -- For example.
ds:SetAsync("defined_test", 8)

That would set the key of "defined_test" to 8. Simple, right?


ds:GetAsync(key)
Remember how I mentioned earlier that you use the SetAsync method to save your key and value? Yeah, that comes in handy now, because you use this function to get your value from your key! Basically, this function returns the value from the key given (as the parameter.) So, let's edit our script from earlier:

local ds = game:GetService("DataStoreService"):GetDataStore(game.Name)
ds:SetAsync("defined_test", 8)
print(ds:GetAsync("defined_test")) --This would print 8.

Basically, we set the key "defined_test" to the value 8. Then, we printed the value by getting it from the key. If you want to use it later, and conserve space / data in your script (idk), then we can do this:

local ds = game:GetService("DataStoreService"):GetDataStore(game.Name)
ds:SetAsync("defined_test", 8)
local value = ds:GetAsync("defined_test")

And there you go!


There are more methods/functions/events in the wiki page I gave you at the beginning, so go check it out! Now, using the the things you learned in here, I will give you a challenge.

In your wiki page, make a leaderboard script. Not just any leaderboard script. A DataStore leaderboard that saves each player's stats. Only make 1 stat per player, because if you make too many, you will reach the limit / higher and your data stores won't work. When you are finished, make a model of it, and send it to me! :D

So basically, to sum up this tutorial, this is what you learned:
Setting a variable to getting the data store.
Setting a key to the data store.
Getting the value from that key.
And there is much more you can do with data stores.

Oh, and something else.
STOP USING DATA PERSISTENCE. :)

/: Nub Scripter : Lecturous :\
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
18 Mar 2015 01:39 PM
"STOP USING DATA PERSISTENCE. :)"
Even better:

STOP CONCATENATING BLANK STRINGS! >:|
Report Abuse
Lecturous is not online. Lecturous
Joined: 17 Aug 2013
Total Posts: 1096
18 Mar 2015 01:40 PM
tru dat, jarod.

/: Nub Scripter : Lecturous :\
Report Abuse
micke3212 is not online. micke3212
Joined: 24 Nov 2009
Total Posts: 3000
18 Mar 2015 02:42 PM
You forgot the part about how SETASYNC DOESNT SAVE RIGHT THEN SO YOU HAVE TO USE UPDATEASYNC. Also you forgot about the events and other methods crucial. The biggest issue with DataStores is understanding the difference between UPDATEASYNC and SETASYNC.

-On iPhone my phone auto corrects everything I do including capitalizing Lua. :(
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
18 Mar 2015 02:46 PM
Actually, SetAsync DOES save right then, but it is just cached. And UpdateAsync is not instant either.
Report Abuse
micke3212 is not online. micke3212
Joined: 24 Nov 2009
Total Posts: 3000
18 Mar 2015 02:51 PM
They updated it?

You see, I've tried to use SetAsync to cross servers while testing. I used a simple global chat gui that I created, it took 10 minutes for one message to appear on the other server. How does this automatically save?
Report Abuse
Lecturous is not online. Lecturous
Joined: 17 Aug 2013
Total Posts: 1096
18 Mar 2015 03:08 PM
bump
and also, I didn't say EVERYTHING about Data Stores, but I redirected people to a wiki page explaining more stuff

/: Nub Scripter : Lecturous :\
Report Abuse
Lecturous is not online. Lecturous
Joined: 17 Aug 2013
Total Posts: 1096
19 Mar 2015 02:12 PM
bump[2]
wait bump isn't a table
DUN DUN DUUUUUUUUUUUUUUUN

--{ Lecturous }--
Report Abuse
Lecturous is not online. Lecturous
Joined: 17 Aug 2013
Total Posts: 1096
22 Mar 2015 11:51 AM
bump[3] :D
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
22 Mar 2015 11:55 AM
My guide is much simpler:

Define DataStores

local DataStores = game:GetService("DataStoreService")


Get a DataStore

local DS = DataStores:GetDataStore("Name")


Set a value

DS:SetAsync("Name", "Value")


Get a value

DS:GetAsync("Name")


Update a value, use this ONLY if you need the previous value:

DS:UpdateAsync("Name", function(old) --old is the old value
return NewValue --NewValue is what you're setting the value too.
end)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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