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

As stated several times before in this thread, just like normal data stores DataStore2 can store dictionaries, tables, etc.

2 Likes

@Kampfkarren I’m sorry, i just realized i wasn’t being clear enough. I meant a dictionary within a dictionary. I was trying this and i’m not having luck looping through this to see if it was working.

  Consumables_Store:GetTable({
	["Simple Potion of Healing"] = {["Description"] = "A Potion of simple healing and stuff", ["Item_Count"] = 3, ["Strength"] = 25, ["Equipped_To_Toolbar"] = false, ["Toolbar_Binding"] = "1"};
	["Simple Potion of Energy"] = {["Description"] = "A Potion of simple Energy and stuff", ["Item_Count"] = 5, ["Strength"] = 23, ["Equipped_To_Toolbar"] = false, ["Toolbar_Binding"] = "2"};
})

 local Consumables_Store_Gotten = Consumables_Store:Get()

  for dicname, dicvalue in pairs(Consumables_Store_Gotten) do
	local Item_Folder = Instance.new("Folder")
	Item_Folder.Name = dicname
	Item_Folder.Parent = Consumables_Folder
	print(dicname)
	for statname, statvalue in next(dicvalue) do
		print(dicname, dicvalue)
		if type(statvalue) == 'number' then
			local intvalue = Instance.new("NumberValue")
			intvalue.Name = statname
			intvalue.Value = statvalue
			intvalue.Parent = Item_Folder
		elseif type(statvalue) == 'boolean' then
			local boolvalue = Instance.new("BoolValue")
			boolvalue.Name = statname
			boolvalue.Value = statvalue
			boolvalue.Parent =  Item_Folder
		elseif type(statvalue) == 'string' then
			local stringvalue = Instance.new("StringValue")
			stringvalue.Name = statname
			stringvalue.Value = statvalue
			stringvalue.Parent = Item_Folder
		end
	end
end

as an example

Dictionaries within dictionaries can still be saved just fine. From a quick skim, your issue is probably here:

You’re using next wrong, just use pairs.

1 Like

Thank you very much. I’m slappping myself in the forehead… i feel silly. You are truly awesome for responding so quickly. Thanks!

1 Like

Hi! :D
I’ve been tinkerin’ around with datastore and I just thought, is there any way to see which version you are on if you require the module? If not, I suggest printing the version the first time that version is required

1 Like

If you require by ID, you’re on an outdated version anyway because I can’t upload the module right now. I strongly recommend you instead just download the release on GitHub for a number of reasons.

Thanks, I’ll try, although you didn’t answer my question… :frowning:

EDIT Also I suggest you make a Frequently asked questions block in this thread to avoid answering to the same thing over and over

I misunderstood your question, sorry (I replied at 1:30 AM). No, there’s no way to check version, the best way to be to add a comment since I don’t really like how DataStore2 prints stuff out in the first place.

1 Like

Thanks for making this nice module !

it is so easy to use

1 Like

grafik
I have to save data, but not for player is this possible with datastore 2.0 ?

What are you actually trying to do? The second argument is meant to be the player.

If you’re trying to save a table, literally just treat it the same way you would any other value–:Get() it, manipulate it (insert etc), and :Set().


i want to do:

Limited Item System!

1.) player touch this colorfull part
2.)The name safe into the datastore
3.) Server tell all exist other server the part have to remove (with server messaging)
4.)all new server know becourse of the datastore that the part have to remove

I do it already with the normal datastore, but i think your code is better :)!

Sry for my grammer i speak german :slight_smile: !
Greetings kevini44

function AddString(strn)

local success, err = pcall(function()
	store:UpdateAsync("rare", 
		
		function(oldValue)
	local t = oldValue or {} 
			table.insert(t,strn)
		return t
	end)
end)
if not success then
	table.insert(datastore, AddString(strn))

	return "fail"
end
print("success")
return "success"

end

function getItems()

local success, itms = pcall(function()

return store:GetAsync(“rare”)
end)
if success then
Items=itms

	if Items==nil then
		Items={}
	end
else

	table.insert(datastore,getItems())
	return "Try Again"
end

end

1 Like

Great work! I’m not interested in the Promise dependency, however.
I would be interested in a light version without Promise.

Sorry, but I’m completely unsure of what you’re asking.

For reference, the Promise dependency is included with DataStore2 itself since it’s just one file–you don’t have to deal with any hassles of updating it, needing to use git submodules, etc.

I can look into making promises optional, but for now you can use an older version without them:

The only notable exclusion thus far is the lack of ability to save using normal data stores and not the berezaa backup method.

1 Like

Do you know any timeframe for an update that would include auto-combine?

1 Like

Not an exact ETA, but I know what needs to be done before it:

Is there a way to create like a datastore that’s not specific to a player - like a server datastore? For example, if someone was banned from the game using an in-game command, would it be possible to save that name or userid using DataStore2?

Is there a way to get a “top 10” for a DataStore2? Just like with an OrderedDataStore with the default DataStoreService.

1 Like

No–there wouldn’t be any point to it. What good would backups do in that case? Just use normal data stores.