DataStores - Beginners to Advanced

I don’t see what you would learn from this? How would this help you? DS2 already gives you almost everything you need. The only thing it doesn’t give is a feature for OrderedDataStores(For example a Global Leaderboard) but with 5 minutes of forking, I got it to work.

2 Likes

If you just want to have a safe DataStore, you should use DataStore2 or ProfileService, but if you want to know how they work or script your own, this tutorial could definitely help you I think.

I personally don’t like just using a module without having an idea of what and how it does the things mentioned.

6 Likes

If your getting into scripting and you really want to learn how to script then this tutorial is far better than using Datastore2. I mean yeah of course DataStore2 is going to be better since it’s been through tons of testing but this tutorial is just explaining how Datastores work and how you can implement one yourself. At the end of the day it’s just your personal preference. If you decide to make your own datastore in the future this tutorial will be useful. Anyway have a good day! Nice tutorial :smiley:

5 Likes

What do you mean by this? I cant understand this

2 Likes

Great tutorial! This is super useful to use! Keep up the great work!

1 Like

I parented the stuff at the end. Instead of something like:

local leaderstats = Instance.new("Folder")
leaderstats.Parent = player
leaderstats.Name = "leaderstats"

local cash = Instance.new("IntValue")
cash.Parent = leaderstats
cash.Value = data
cash.Name = "Cash"

I did

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"

local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = data

cash.Parent = leaderstats
leaderstats.Parent = player

I did that because if GetAsync yields (stops the thread, takes some time, then continues), and we parented the stuff before setting the value, we would have no way of knowing if the data has loaded or not yet.

Even if we parent them to leaderstats after the data has loaded, we would have to use WaitForChild for every single IntValue. So I didn’t parent leaderstats at the beginning but at the end when everything is done, this way, we only have to use WaitForChild for the leaderstats.

You can also do

local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"

local cash = Instance.new("IntValue")
cash.Name = "Cash"
cash.Value = data
cash.Parent = leaderstats

leaderstats.Parent = player

That does the same thing if that’s more clear for you, the point is to parent the leaderstats at the end.

2 Likes

This is such a good tutorial! It’s helped me a lot, and I’ve already implemented parts of these scripts into projects of mine!

1 Like

Hello, I followed the tutorial, but in my game, leaderstats is not showing up.
This is what I wrote for my script:

local function setUp(player)
	local userId = player.UserId
	local key = "Player_" .. userId
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	
	local money = Instance.new("IntValue")
	money.Name = "Money"
	
	local data = dataStore:GetAsync(key)
	
	money.Value = data or 0
	
	money.Parent = leaderstats
	leaderstats.Parent = player
	
end

I don’t know what I am doing wrong. Thank you.

Are there any errors in your output? Maybe you didn’t enable API Services.

Is that your whole script?
That’s just a plain function, you have to connect it to PlayerAdded and make a PlayerRemoving function too.

1 Like

There isn’t any errors, or warnings in my output.
Also, I did write the script for PlayerAdded, PlayerRemoving, and AutoSaving.

The script used to work, but ever since I added another IntValue to the leaderstats script, the leaderstats stopped showing.

Sorry for the late reply but could you give an implementation example because I am stuck looking at the scripts and what you had recommended

1 Like

Just realized I was a noob at datastores (which is a good thing. I can improve on datastores now). Will finish reading through this sometime later. So far, this tutorial is the best I’ve seen for datastores!

1 Like

I don’t think you should use wait() for event based situations like this. This is known as polling and even though we won’t see a delay, it is confirmed that it will wait some more extra milliseconds. For this, you could use a BindableEvent and use the BindableEvent.Fire:Wait() to save that extra milliseconds. You probably need a timer module or create your own wait() function to fire the BindableEvent every once a minute.

1 Like

Wow nice, how did you make the code look like that? :thinking:

3 Likes

Some people don’t want to use DS2, for example it doesn’t have session locking, and I have seen posts where dataloss has occured using DS2. DS2 is outdated now and hasn’t been updated since nearly 2 years ago.

1 Like

It is not outdated. Its been upated in the last 4 months.

It is still rarely updated, and backups aren’t really that important, how is this tutorial not helpful, a LOT of people want to do it themselves which means they are in control.

2 Likes

they are also in control by forking datastore 2?

This is very well one of the best tutorials I have ever read or seen. This is absolutely amazing and you went above and beyond with this one. I will definitely use this again in the future and recommend it to others, you did a great job.

3 Likes