How to use DataStore2 - Data Store caching and data loss prevention

If i have a sub place called B and the main game is A would the data of A transfer to place B and if any values changes in place B would it change to Place A? Using your DataStore2 Module

1 Like

Yes, I think it would be added.

local Classes = DataStore2("Classes", Player):GetTable({})
Classes.Assualt.Exp = 0
DataStore2("Classes", Player):Set(Classes)
--You could also use the :Update() function

I think it will work like this if I remember how to correctly work with tables haha.

I’ve been trying to debug this for the past 30 minutes. My data isn’t saving. image image image

I am so confused. I tested in a real game, in studio with SaveInStudio enabled, etc. So I have resorted to asking on this thread. Everything else saves perfectly. This doesn’t.

EDIT: Fixed this by updating my DataStore2 files from the release on github to the newest.

Thank you for giving us this marvelous masterpiece! It has a very easy API documentation to get into and it really paces up the progress of creating a game.

@Kampfkarren How would I go about saving in-game items in a game, so for example if a player purchases a sword and when the player rejoins next time then the sword will be on their inventory since they have already purchased it.

Do I create another key under the masterKey?

I’m not sure the question here really, it’s the same way you’d save anything else which the documentation should suitably answer.

1 Like

Is it still normal for it to take 30 seconds to end testing in studio and getting “Not running script because past shutdown deadline”? I’d assume it’s due to the BindToClose Roblox bug but I thought that would have been fixed already? Is anybody else having this issue?

Do you have data stores enabled? It’s possible it’s repeatedly trying to save, but can’t.

Thanks for the response, yes I do.

Not completely sure other than perhaps check if there’s any other stack traces.

I have a way of saving items in my game called A Test in Time using DataStore2.

The way I do it is that when a player joins the game, I create a function which returns a table with a table that has values indicating the items. Then, I create a new DataStore called UserData using DataStore2; I am getting the DataStore and inserting the function that returns the table as the default value.
After that, I create a new DataStore for the items. I check if the player has an item by getting the DataStore with the default value of the table for the items in UserData. Also the values for the items are bools. If the player does own the item meaning that the value is true then clone the item from somewhere and put it into the player’s Backpack or Inventory if you have made one.

When buying an item I simply create the same DataStore for the UserData as in when you firstly created it and get it with the default values of the function that returns a table. Then I create the same DataStore for the items the same way I created the UserData datastore and I modify the values for the item that the player is buying and set it to true in UserData. I also check if the item is not other items. If it isnt an other item then set the value in UserData for the other item to the value the item in the items DataStore. Then I set the items DataStore values to the UserData.

Hope this helps! :wink:

1 Like

I solved the problem, it wasn’t even related to Datastore2, so apologies for wasting your time.

By the way, one more question… does DataStore2 save bool values too or only IntValues?

My method of saving saves bool values so yes, DataStore2 also saves bools.

What about other methods like the one OP showed? Yes?

That, I am not experienced enough to know the answer of.

Oh right, basically I am creating a boolean value to check whether a player should permanently keep an item so if its set to true then whenever the player has joined the game next time then it will make sure to give that item to the player.

I was going to create something like this but I’m not sure if this is a better way, your method seems complicated:


local DataStore2 = require(game.ServerScriptService.DataStore2)

local EnabledData = DataStore2("EnableData", plr)

local EnableFolder = Instance.new("Folder", plr)
EnableFolder.Name "EnableFolder"

local RedTrail = Instance.new("IntValue", EnableFolder)

RedTrail.Name = "RedTrail"

local function Update(value)
          RedTrail.Value = EnabledData:Get(value)
end

EnabledData:OnUpdate(Update)
Update(EnabledData:Set(true))

So the boolean is set to true and if the player has joined again then it will check if its true, if its true then it will give you that item.

This probably won’t make sense but I am tryinf to find a better method.

Well, good luck finding a better method.

Did you see the DataStore key in my code?

Nevermind! Your method works just fine, thanks for spotting that method out for me.