Data save wont save clothes

I want to save the shirt and pants of a character when they leave the game.

The problem I am having is that the CharacterRemoving function won’t add the clothing Id’s to the dictionary. I am getting no errors in the output as well.

I have tried printing the id’s. They print out but they don’t get added or saved to the dictionary

This is the part where I try to save the characters clothes when they leave. (This is only part of the script)

local SavedItemIDs = {

}
game.Players.PlayerAdded:Connect(function(player)
	
	player.CharacterRemoving:Connect(function(character) --area that needs work ↓
		local shirt = character.Shirt --Shirt
		SavedItemIDs["Shirt"] = shirt.ShirtTemplate
		print(shirt.ShirtTemplate)

		local pants = character.Pants --Pants
		SavedItemIDs["Pants"] = pants.PantsTemplate
		print(pants.PantsTemplate)
	end)

Any assistance on what I am doing wrong is appreciated. Not looking for any scripts I’m just looking for guidance.

Btw this is under the PlayerAdded function.

I just tested your code and it works fine for me. I printed out the dictionary:

{
    ["Pants"] = "http://www.roblox.com/asset/?id=2940661125",
    ["Shirt"] = "http://www.roblox.com/asset/?id=3420854498"
}

Maybe try using humanoid.Died instead? The only difference is that humanoid.Died fires right when you die, instead of right before your character despawns.

local SavedItemIDs = {

}
game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		character:WaitForChild("Humanoid").Died:Connect(function()
			local shirt = character.Shirt
			SavedItemIDs["Shirt"] = shirt.ShirtTemplate
			print(shirt.ShirtTemplate)

			local pants = character.Pants
			SavedItemIDs["Pants"] = pants.PantsTemplate
			print(pants.PantsTemplate)

			print(SavedItemIDs)
		end)
	end)
end)
3 Likes

But why do I have to use humanoid.Died when I’m trying to save the clothes when they leave?

1 Like

If you want to save when they leave then you should use the Players.PlayerRemoving event

1 Like

I tried that and I had no luck. How am I going to get the characters shirt and pants when they already left.

1 Like

Maybe you could save each character in a table when they are removed then reference them at the end? For example:

local Players = game:GetService("Players")
local characters = {}

Players.PlayerAdded:Connect(function(player)
    player.CharacterRemoving:Connect(function(character)
        character.Archivable = true
        characters[player.UserId] = character:Clone()
    end)
end)

Players.PlayerRemoving:Connect(function(player)
    local character = characters[player.UserId]
    -- save shirt and pants
end)
1 Like

Nothing is working at the moment

1 Like