New clothing on CharacterAdded event

  1. What do you want to achieve?
    The title says it.
  2. What is the issue?
    The old clothing of the player’s character doesn’t get destroyed.
  3. What solutions have you tried so far?
    I tried parenting the old clothing to e.x: ReplicatedFirst, but also didn’t work.
    Unbenannt
    The script below is located in ServerScriptService.

local RS = game.ReplicatedStorage
local Pants = RS.Pants
local Shirt = RS.Shirt
game.Players.PlayerAdded:Connect(function(Plr)
	Plr.CharacterAdded:Connect(function(char)
		--
		local oldpants = char:FindFirstChild("Pants")
		local oldshirt = char:FindFirstChild("Shirt")
		--
		if oldpants then
			oldpants:Destroy()
		end
		--
		if oldshirt then
			oldshirt:Destroy()
		end
		--
		local CloneShirt = Shirt:Clone()
		local PantsClone = Pants:Clone()
		--
		CloneShirt.Parent = char
		PantsClone.Parent = char
		--
	end)
end)

The issue is probably that the shirt and pants aren’t loading in by the time the if statement runs. Use WaitForChild instead of FindFirstChild

1 Like

Thank you for your help it worked!