Datastore2 added to queue issue

When multiple people join my game at once datastores load very slowly or don’t load at all! The console says that the the datastores were added to queue.

I’ve tried combining some datastores but i’m still here with 9 different datastores. I’ve also tried loading the datastores at different times, but that still does not seem to work.

Is there any way i can fix this or combine the datastores without loosing data? (I use datastore2 for most of the datastores btw)

2 Likes

Hi, I’ll recommend you to use :UpdateAsync(function() instead of the :SetAsync() if that’s what you are doing.
Note: The :UpdateAsync(function() might be hard if it’s your first time using it.
Note 2: The :UpdateAsync(function() clears everything and changes the data fully.

2 Likes

Hi, I use this for my game, and it is approved by the creators of Datastore2:

This is a system for Money:

local DataStore2 = require(game:GetService("ServerScriptService").DataStore2)
local CombinedDataStore = DataStore2.Combine("Money", "MoneyBackup")

local DefaultTable = {
	["Money"] = 10, -- 10 is the default amount
--  you can also add more currencies here as well. 
}

game:GetService("Players").PlayerAdded:Connect(function(Player)
	local DataStore = DataStore2("TimeTrials", Player)

	local DataTable = DataStore:GetTable(DefaultTable)

	local Data = Instance.new("BinaryStringValue")
	Data.Name = "Currencies"
	Data.Parent = Player

	for Map, Value in pairs(DataTable) do
		Data:SetAttribute(Map, Value)
	end

	for Map, Value in pairs(DefaultTable) do
		if not Data:GetAttribute(Map) then
			Data:SetAttribute(Map, Value)
		end
	end

	Data.AttributeChanged:Connect(function()
		local DataToSave = {}

		for Map, Value in pairs(Data:GetAttributes()) do
			DataToSave[Map] = Value
		end
		DataStore:Set(DataToSave)
	end)
end)

To change the currency, simply do

Player.Currencies:SetAttribute("Money", Player.Currencies:GetAttribute("Money") + 10) -- To add 10 to the currencies

Let me know if you need help!


He is using a custom module, Datastore2.

1 Like

Yeah, but this happens when people join! It wont load the datastores

1 Like

You should be using only 1 datastore. 9 is way too many, its as if 9 players joined at once.

Put all data into a singular table, and save the table.

Is there a way to do that without loosing data?

You’d need to write something that converts it to the new store.

When a player loads data, check if the new datastore which would be the table exists, if not then load the 9 datastores, convert it to a table, and use that table for saving. If the data does exist, then don’t load the other 9 datastores, since the player has data in the new datastore.

1 Like

thanks, i’ll give it a try! (character limit)

ok, so I’m writing the script but on PlayerAdded, when I check if the player has used the ‘new’ datastore, I don’t know if it’s just a new player, OR if it’s a player that has played with the ‘old’ datastore.

Nevermind i think i figured it out, i did (if NewDataStore is not nil, then load NewDataStore) ELSEIF (NewDataStore is nil and the player HAS played before, then load OLD data) ELSEIF (NewDataStore is nil and the player HAS NOT played before, then load NewDataStore.

i know its kinda confusing lol, but is it a good way to do it?

Yeah thats how I’d do it. Best way I can think of.

1 Like