Table isn't being saved by DataStore

Hello Everyone.

I am working on an editor that allows you to change decorations of a Christmas Tree. And of course, one of these decorations is ornaments, which I’m currently testing.

I’ve created a script that saves a table with datastores, this table contains the necessary data to eventually load the Tree, currently the only thing stored in it is a color3.

However, The script doesn’t seem to be saving the table’s contents. Either it needs to be physical somehow or the inserted data itself has to be saved, I don’t know.

This is my code:

local dataStoreService = game:GetService("DataStoreService")
local TreeDataStore = dataStoreService:GetDataStore("TreeDataStore")

local TreeData = {}

game.Players.PlayerAdded:Connect(function(player)
	table.insert(TreeData, {R = 255, G = 0, B = 0})
	
	local success, TreeData = pcall(function()
		return TreeDataStore:GetAsync(player.UserId, TreeData)
	end)
	if not success then
	   wait("Error Getting TreeData")
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local success, errorMessage = pcall(function()
		TreeDataStore:SetAsync(player.UserId.."TreeData", TreeData)
	end)
	if errorMessage then
		wait(error())
	end
end)

This is the error message I’m getting when I check to see if it works:
image

Thank you.

1 Like

Make sure the table doesn’t have any things that cannot be saved, ProfileService has a list of things that can’t be stored on table stores, and that lines up with ROBLOX’s built in datastore limits. So check this: Troubleshooting.

1 Like

You are setting async with the key of PLAYER USERID with “TreeData” string connected, but you are only getting async with key of ONLY player userid, thats why it doesnt return anything

1 Like

set your async like this

		TreeDataStore:SetAsync(tostring(player.UserId).."-TreeData", TreeData)

and get ur async like this

	local success, TreeData = pcall(function()
		return TreeDataStore:GetAsync(tostring(player.UserId).."-TreeData", TreeData)
	end)
2 Likes

Oh my god, I totally overlooked that. Thank you so much.

2 Likes