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
end
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
end)
if Error then
warn(Error) -- Showing there was error (Can also keep in log to fix)
end
end)
game:GetService("Players").PlayerAdded:Connect(function(Player)
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
end
end
end)