Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I deal with tables in a datastore?

Hi guys, I'm struggling with this datastore stuff... Idk why I can't understand it :P

The following code pretty much sums up my problem:

local data_store_service = game:GetService("DataStoreService")

local function player_added(player)
	local scope = "player_" .. player.UserId
	local player_data = data_store_service:GetDataStore("player_data",scope)
		local experience = player_data:SetAsync("experience",0)		
		local resources = player_data:SetAsync("resources",{})
			local wood = --how do I get a number value with the key "wood" inside of the resources table?
		
	local bank_data = data_store_service:GetDataStore("bank_data",scope)
end

game:GetService("Players").PlayerAdded:connect(player_added)

How do I add values into the table? If I make the line read: resources["wood"] = 0, I get an error saying that resources is a nil value...

I would usually have all of this stuff stored as values in a folder in serverstorage so it wouldn't be a problem but i'm trying to move away from that...

Thanks for your help guys, I think it's a really easy question tbh but I can't figure it out haha

P.S. If anyone know of a good place to learn about how to setup large datastores (all I can find is could you please leave a link? ty :)

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.