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

Would it still be a good idea to just require the model you have on ROBLOX? I’m only asking because I don’t see that in your post anymore and noticed it hasn’t been updated since August.

1 Like

No, I don’t recommend this anymore. That model is outdated and Roblox Studio isn’t letting me update it.

4 Likes

Is it not possible to get player data for players that are not in the server? My use case is teleporting players to their friends who are in reserved servers using a reserve code stored in the friends datastore. But you can only retrieve datastores with player instances.

Something like…

local FriendPresenceStore = DataStore2("Presence", FriendUserId)
local Presence = FriendPresenceStore:Get({})
local PlaceId = Presence.PlaceId
local ReserveCode = Presence.ReserveCode
FriendPresenceStore:UncacheWithoutSaving() -- For example.
3 Likes

I’ve answered this several times in the thread, but no. This is planned, but no work has been done: A way to get data of an offline user · Issue #44 · Kampfkarren/Roblox · GitHub

2 Likes

this may be a silly question but, does the data save across places within games (for example will your “XP” value be the same in the Hub as Level1)

1 Like

Yes, I’m using this in a multi-place game and it works fine. Just make sure to save the player’s data before teleporting them.

2 Likes

He has answered a question similar to this before.

1 Like

i cant open in rbxmx file in my roblox studio only rbxl

Simply drag and drop the file on your studio application and it will insert the rbxmx file.
https://gyazo.com/4f607bf77f113fc5e9232199a1776025

2 Likes

Thank you so much :slight_smile: #30characters

1 Like

When a store is set as a backup, when should we know to clear it?
Should I set up something that checks every now and then to see if the DataStore is still failing, and then clear the backup when it succeeds?

@Kampfkarren

I’m not sure, you should be able to get away with never clearing it, as I wouldn’t expect the player to stick around anyway.

Would this be an effective way to store item ownership in DataStore2?

local inventory = {"Sword", "Baton"}
local defaultItems = {Sword = true}
DataStore2.Combine("Items", unpack(inventory))

local function PlayerAdded(player)
    for _, item in pairs(inventory) do
        local store = DataStore2(item, player)
        local owned = store:Get(defaultItems[item] or false)
        -- do stuff
    end
end

EDIT: I’ve been reading up on the API docs, and it seems that serialization is a good way to do this. However, I’m using combined data stores to sore currency amounts and it seems that serialization doesn’t work well with combined data stores??

It’s worth a try anyway, FMPOV.

1 Like

When would you actually use :ClearBackup() then?

It’s mostly there for API completion I suppose, though it sounds like a good idea to just not use it if you aren’t already knowledgeable on the best way to do this? Sorry for the unclear answers.

This problem occurs only in studio testing right? Not in real servers?

1 Like

This is a truly epic module, but something (I’m not sure what) happened and now the :BindToClose function keeps causing my game to output this:
image
The :BindToClose function isn’t present in any of my other scripts either. Can any of you try and find out what’s wrong? (Also this started like five seconds ago, haven’t had this issue with the module before)

1 Like

This is a Roblox bug.

2 Likes

Is there a way to save data without involving a player? Such as if you want to save a global value instead one that is directly related to a specific player. For example:

DataStore2("Key"):Set(true)