Player's Original Clothes don't Properly Delete

For more understanding with the title, I mean that the script doesn’t delete the clothes for a specific team what the script does is to check if you have clothes on and if so it deletes it. But it does equips the clothes but It doesn’t delete the Player’s original clothes. So, basically sometimes the clothes will be layered.

function addClothing(player: Player, character, hum: Humanoid)
	repeat task.wait() until player.Character
	repeat task.wait() until player:HasAppearanceLoaded()
	if player.Team == nil then return end

	if rs:FindFirstChild("Teams"):FindFirstChild(player.Team.Name) then
		for i, clothing in pairs(rs:FindFirstChild("Teams"):FindFirstChild(player.Team.Name):GetChildren()) do
			if clothing:IsA("Shirt") or clothing:IsA("Pants") then
				if character:FindFirstChild(clothing.Name) then
					character:FindFirstChild(clothing.Name):Destroy()
					print("Deleted clothes")
				end
				
				clothing:Clone().Parent = character
				print("Inserted clothes")
			end
		end
	end
end

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		addClothing(Player, Character)
		Player:GetPropertyChangedSignal("Team"):Connect(function())
			addClothing(Player, Character, Humanoid)
		end)
	end)
end)

image

1 Like

Hey you should look into HumanoidDescriptions. HumanoidDescription | Roblox Creator Documentation

local PlayerService = game:GetService("Players")

PlayerService.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		repeat task.wait() until player.Character
		repeat task.wait() until player:HasAppearanceLoaded()
		
		local humanoid = character:WaitForChild("Humanoid")
		local description = humanoid:GetAppliedDescription()
		description.Shirt = 0 -- id of shirt
		description.Pants = 0 -- id of pants
		humanoid:ApplyDescription(description)
	end)
end)
3 Likes