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

i know i am doin it but when i require through id it doesnt work in studio so i have to do something like this

local DataStore2

if RunService:IsStudio() then

DataStore2 = require(game:GetService(“ServerScriptService”):WaitForChild(“MainModule”))

else

DataStore2 = require(1936396537)

end

1 Like

Probably. I just haven’t gotten around to it. :stuck_out_tongue:

Please read my post nearly directly above yours. Do not require by ID–the free model is horribly outdated.

1 Like

Do we get it from GitHub? Sorry btw, a bit confused

Yes, you can get an updated version there. Simply download the file, and insert it into studio.

1 Like

Please read the documentation.

https://kampfkarren.github.io/Roblox/guide/installation/

1 Like

Small question:
Is there a performance difference between saving data as a table/dictionary containing all saved data and saving data under different subkeys using combine? Is one method preferred above the other?
I’m curious as I have a lot of data to save, like money, xp, level, bought tools, inventory and so on.

Saving an entire table to a single key defeats the purpose of combined data stores.

1 Like

I tried switching to the new datastore2 script that you told us to download instead of using the free model one but some other players still lose their data although me personally doesn’t experience it. My game involves updating a player’s mileage by calling :Increment() every second through a remote event and at high speeds. And yes, my script references a couple tutorials out there by combining Alvin_Blox and other people’s tutorials although there’s nothing that teaches us when dealing with multiple stats and has a global leaderboard that updates every minute using a regular ordered datastore. I’m just tryna highlight some of the main processes that occur in my game involving datastores and idk which one of these causes it.

1 Like

You should combine keys and use them directly because it’s more ergonomic.

Incrementing every second is fine since it’s not actually writing to a real data store. I don’t know what to do with this much information other than tell you that it’s most likely a you problem.

Hello where can I find the latest version of the DataStore2 file.

1 Like

Did you check the GitHub releases page linked near the top of the original post?

1 Like

Is it possible to use a normal datastore next to datastore2? Or could it throttle even when configured correctly? A use case could be having a seperate datastore for global game data such as events / purchase history

1 Like

It’s possible, yes.

1 Like

Will DataStore2 introduce Session Locking anytime soon?

Hello @Kampfkarren,
Most of my players experienced a datastore2 loss data when they returned to the main lobby from the multiplayer place (sub-place) under the same game.

1 Like

Datastore2 requires you to call an update function like :Set() or :Update() whenever the data actually changes and this is okay because the module caches. Are you updating ammo, or is it some other piece of player data?

1 Like

DataStore2 is open source. If you want to contribute session locking, you’re free to do so. I have zero use case for it, so until I do I’m not implementing it myself.

Are you saving before teleporting? If not, you should do so.

1 Like

@Kampfkarren I have the same issue. It would be better to call indepent saves on each of those values affected by data loss (2 tables and 5 values) or a full SaveAll() before teleporting?

EDIT: i put a SaveAll() before the teleporting and one of the tables didnt save for a user.