Datastores not wanting tables

i stole this script from another forum, apparently datastores can’t be given tables, what other way is there where can i save/load the contents of a folder?
( the folder has StringValues in it )

local dataservice = game:GetService("DataStoreService")
local inventorydata = dataservice:GetDataStore("Inventory")
local itemsfolder = game.ServerStorage.Skins

game.Players.PlayerAdded:Connect(function(player)
	local inventory = inventorydata:GetAsync(player.UserId) or {}
	for i, si in pairs(inventory) do
		if itemsfolder:FindFirstChild(si) then
			itemsfolder.si:Clone().Parent = player.Inventory
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local inventory = {}
	for i, si in pairs(player.Inventory:GetChildren()) do
		table.insert(inventory,si)
	end
	local success, errormsg = pcall(function()
		inventorydata:SetAsync(player.UserId, inventory)
	end)
	if errormsg then 
		warn(errormsg)
	end
end)

( gives me the error “104: Cannot store Array in data store. Data stores can only accept valid UTF-8 characters.” )

https://create.roblox.com/docs/reference/engine/classes/HttpService#JSONEncode
https://create.roblox.com/docs/reference/engine/classes/HttpService#JSONDecode

You can’t store instances in DataStores. Try saving the item names instead! Then it can properly load them once they rejoin.

4 Likes

Datastores can store tables, but the values inside the table must be themselves allowed to be saved (any roblox object or datatype usually is not accepted, but stuff like number, string, booleans, buffers, those are accepted)

The answer above found your problem

2 Likes

srry for late reply, had to go, tho yep this worked!

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