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

Quick question:
How would I loop through all of the datastores under a certain player?

Why it doesn’t make sense, my game is slowing down a lot because of onUpdate
(sorry for such a long period of time)

My game when player leave it save but when game shutdowned it doesnt save why? I used the latest datastore2 module from github, i tried to use SaveAll loop make more broken like when the server getting slower when leave it wont save the data :frowning:

Would you be able to give an example on how “:GetTable()” is supposed to work?

Im trying to add a table array of stats (Tools owned) into my data, but only it has worked for me. It errors every other time. The code I used:

local function UpdateGears(Val)
		GearTable = GearStore:GetTable(Val)
		GearsFolder:ClearAllChildren()
		for _,v in ipairs(GearTable) do
			local gValue = Instance.new("BoolValue")
			gValue.Name = v
			gValue.Parent = GearsFolder
		end
	end

for _,v in pairs(GearStore:GetTable("Gears")) do
		if not plr.Backpack:FindFirstChild(v) or not plr.StarterGear:FindFirstChild(v) then
			local clone = Gears[v]:Clone()
			local clone2 = Gears[v]:Clone()
			clone.Parent = plr.Backpack
			clone2.Parent = plr.StarterGear
		end
	end

The error id get is:

invalid argument #1 to ‘pairs’ (table expected, got string)

Any help is appreciated!

Nothing in what you’re doing makes sense to be using GetTable. Why not just use Get() instead? It works on tables.

1 Like

will this module work good

according to QuickNetwork - A powerful hybrid alternative to ProfileService and DataStore2

who seems like a guy who’s over boasting who said this is outdated and even you admitted

should i use this over profileservice and Quicknetwork

–skyquest

is anyone going to answer this :frowning:

That module is long gone since 10 months, and the topic has been locked as well, there is absolutely no reason for you to use that module.

Using this or profile service should be decided by your self, based on your needs. ProfileService offers a powerful API and has session locking with one of it’s primary features, whereas DataStore2 offers a somewhat bloated API (but a lot comprehensible) and has backups as it’s main feature. With that being said, I highly recommend using ProfileService.

1 Like

yes i agree in some parts

agrees
the module is long gone ( there was no update and this thread seems to dead )

datastore2 is bloated ( very agreeable )
disagrees
datastore2 backups ( its totally useless now since versioning exists )

conclusion

i will try out profile service it seems pretty popular currently

and thanks for tanking your time to answer this question

Here’s an updated version where you can call it using instances or player’s userid:

@Kampfkarren
Thank you for sharing us this wonderful module. Here’s changes I’ve added:

  • Detects 2nd parameter if it’s Instances or Player’s UserId
  • If 2nd parameter is Instance, set Instance to Instance’s UserId
  • Checks if Player’s Instances of Player’s UserId exists
  • Checks if Player’s Instances exists and if so, then create an AncestryChanged event.

And then modified your quick hacks:

Works wonder, it prints all the datas of other players even without being in-game. Useful for these:

  • ROBLOX’s Right to Erasure - Action Requested
  • Admin Abuse Data Reset (When an admin in your game abused his powers, you can easily revert back the data)
  • Resets Player’s Data

How to try:

DataStore2(dataName,UserId)

DataStore2:Get(nil)

I printed somebody’s whole data and I can assure you it’s not mine:
image

File:
UpdatedDataStore2.rbxm (18.2 KB)

1 Like

Wait, why should we use your changes rather than the vanilla Datastore2? You never clarified on why I should use yours, and is it backwards compatible with vanilla Datastore2?

Is it possible to create a data store with this module that does not belong to one specific player? As in, a way to make a data store that all the players can access? Should I just use a regular datastore for this?

Another question adding on to this:
If I need to use a regular datastore, does this module work interchangeably so I can use DataStore2 for some data and the regular Roblox datastore for others?

You should use regular data stores with this, you can just use both at the same time.

Hey there! A few questions I would like to ask. I am fairly new with this module and from what I have picked up so far is basically that data gets saved or put on an in game cache which are the keys. The combine basically then takes all the in game cached data and puts into a big table which then gets saved? My first question is, why would you then save a table in the first place if combine does that for you. That just creates more pain as then you have to get the table, and insert your new values compared to just being able to directly update 1 value which later gets put into a table.

Will you implement a function for session locking like profileservice?

Is it ok to save lots of data under keys and not use tables at all?

Would datastore2 be a good module to create a player guild system with?

And finally, using both datastore2 and profileservice wouldn’t work right?

If you answer these questions that would be great man! I am developing an rpg game with lots of systems e.g inventory, character customization, guilds ect. Have a great day and if you reply thx so much!!

No, I never needed it, and nobody has sent a pull request yet.

Yeah, but why are you afraid of tables?

You can only access data from players in game. So probably not.

It’d work fine if you use standard data saving.

Well, I am new to datastores and I have been slaving over for days now trying to save tables and update values in it. Also, I have been scripting on and off for 2 years now and I gotta say the biggest hurdle is not learning how to script, its learning how to script efficiently and have optimized code. I never really took that into consideration so now its like I am screwed. Anyways, thx man for answering

I’m making a slot system, is this an effective way?:

local sss = game:GetService("ServerScriptService")
local DataStore2 = require(sss.MainModule)
local slot = --slotnumber

DataStore2.Combine(
	"DATA", 
	"value1".."Slot"..slot, 
	"value2".."Slot"..slot, 
	"value3".."Slot"..slot, 
)

game.Players.PlayerAdded:connect(function(plr)
	local value1Store = DataStore2("value1".."Slot"..slot, plr)
	local value2Store = DataStore2("value2".."Slot"..slot, plr)
	local value3Store = DataStore2("value3".."Slot"..slot, plr)

    print(value1Store:Get(5))
end)

umm… where is wrong inn my code…i dont think its wrong…can someone tell me where is wrong in my code?..
attempt to index number with ‘Own’

Looks fine, as long as you ensure everything is combined properly.

This isn’t the code that’s erroring, as “Own” is nowhere to be seen.