Datastore not saving table

I have a table which has cars the player has bought, but when i load all the values all of them return false instead of true but i set it to true when i left the game, here is how i save my data:

local DataTable = {}

– when player joins i give them these values:

	DataTable[player.UserId] = {
		["Car2023"] = {
			["Haas"] = false,
			["Williams"] = false,
			["AlfaRomeo"] = false,
			["Alpine"] = false,
			["Mclaren"] = false,
			["Ferrari"] = false,
			["AstonMartin"] = false,
			["Mercedes"] = false,
			["Redbull"] = false
		}
	}

game:BindToClose(function()
	for i, player in pairs(Players:GetChildren()) do
		ItemStore:SetAsync(player.UserId, DataTable[player.UserId])
	end
end)

Players.PlayerRemoving:Connect(function(player)
	ItemStore:SetAsync(player.UserId, DataTable[player.UserId])
end)
2 Likes

Where exactly are they set to true?

1 Like

Hey!
Datastores do not accept things such as Vector3, CFrame, tables etc.

To save a table, use httpServices function JSONEncode which converts the table to a string and save that to datastores. When you load the data you use JSONDecode to convert it from a string to a table.

sorry for the late reply, i have found the issue in my code ages ago, it wasn’t a saving issue i just wasn’t setting the value correctly

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