Load 1 Global Table for all Players

How would I make use of GlobalDataStore to have players update parameters inside the table, and have those load in when other/new players join?

So that basically all players data is synced and the same for everybody.

2 Likes

you can just use a normal datastore with the same key for all data

2 Likes

That’s a good idea, but since when can you not store Dictionaries in DataStore?

And should I be using SetAsync or UpdateAsync on the dataStore?

1 Like

Probably UpdateAsync but it depends on what you’re doing

1 Like

parts color can be changed by players, and so for each time a part is updated the function to save data runs, and so that data should load for all players when they join

1 Like

Updating the datastore every time the color changes is not a good idea, both for avoiding data race conditions across many servers, but also because you’ll reach the datastore call limit really fast.

You should use a mix of MemoryStores for live data editing across many servers, and Datastores for long-term data saving when memory stores expire or a server is closing.

1 Like

But there can only be 1 million parts, if I just update each parts data in the table, the file size should not be able to grow?

1 Like

Yeah, file size isn’t the issue, what’s the problem?
Are you saying that 1 million parts isn’t enough or what?

1 Like

No I said in my game all the colored blocks will never be more than 1 million, so I meant that the file size should never be reached and nothing I need to worry about, anyways I’m saving the parts’s colors as the player leaves now

1 Like
local Key = "Key"
local Canvas = workspace.Canvas

local function Save(player: Player)
	local Data = {}
	print("Saving...")
	for i, Pixel in pairs(Canvas:GetChildren()) do
		table.insert(Data, {
			Pixel.Name,
			Pixel.Color,
			Pixel.CFrame.Position.X,
			Pixel.CFrame.Position.Z
		})
	end
	
	DataStore:UpdateAsync(Key, function()
		return Data
	end)
	print("Saved")
end

Says that I cannot store Array in data store, Data stores can only accept valid UTF-8 characters.
What do I do?

1 Like

Yeah I didn’t mean file size limit I mean the limit on how many datastore api calls you can do, these

1 Like

just do something like this instead

(assuming that each pixel has a unique and unchanging name across servers)

local function Save(player: Player)
	local Data = {}
	print("Saving...")
	for i, Pixel in pairs(Canvas:GetChildren()) do
		Data[Pixel.Name] = {
			Color = Pixel.Color,
			X = Pixel.CFrame.Position.X,
			Z = Pixel.CFrame.Position.Z,
		}
	end

	DataStore:UpdateAsync(Key, function()
		return Data
	end)
	print("Saved")
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.