Skin Saving Script Not Saving

Hello! I’m the scripter of a fairly popular cart ride.
We recently decided to add SKINS, however, the system for saving the skins is not working and I have no idea why. The code simply clones a decal from replicatedstorage and adds it into the player’s Skin folder, there’s no errors, please help me.

local http = game:GetService("HttpService")
game:GetService("Players").PlayerRemoving:Connect(function(Player) -- Checking if player is leaving game
	local InventorySaveTable = {}

	for i, v in next, Player:WaitForChild("Skins"):GetChildren() do
		InventorySaveTable[v.Name] = v.Value -- Assuming all that you want to save are object values
	local Inventory = http:JSONEncode(InventorySaveTable)
	local Success, Error = pcall(function()
		return game:GetService("DataStoreService"):GetDataStore("Skins"):SetAsync(Player.UserId.."Inventory", Inventory)
		-- Setting the data for inventory for the player
	if Error then
		warn(Error) -- Showing there was error (Can also keep in log to fix)
	local Data = game:GetService("DataStoreService"):GetDataStore("Skins"):GetAsync(Player.UserId.."Inventory")
	if Data then
		local decoded = http:JSONDecode(Data)
		--add skin loader here
		for i,v in ipairs(decoded) do
			local skin = game.ReplicatedStorage:WaitForChild(v):Clone()
			skin.Parent = Player.Skins

ROBlOX already JSON encodes and decodes when saving to a data store so there is no point in yourself doing it

but what about a table? Can you save a table in a datastore?

Yes, you can save tables to a datastore, but you don’t need to encode/decode them, as Roblox does this on their back-end servers for you.
Try adding prints to see where the script stops.

I know this is a late response but i’ve edited the code, and now I’m getting this error : invalid argument #1 to ‘ipairs’ (table expected, got string)

It means what you’re trying to loop through, is a string.
You can only loop through a table.

By the way, you don’t need to encode/decode it, Roblox does this already on their servers.

i removed those and started getting the error

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