Players original shirt overlaps custom shirt given to them

Basically I have two teams and each team has its own uniforms and hats. However, whenever I run the game, the players original clothing overlaps the uniform. How can I come to solve this? Any help is appreciated thank you

Players = game:GetService('Players')
Teams = game:GetService('Teams')

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		humanoid:RemoveAccessories()
		wait(2)
		
		local team =  player.Team

		local hat =   team.Hat:Clone() 
		local shirt = team.Shirt:Clone()
		local pants = team.Pants:Clone()
		shirt.Parent = character
		pants.Parent = character
		hat.Parent = character
	
	end)
end)





1 Like

This might be because you have two instances of the clothes. I recommend instead of cloning the clothes and putting them into the player, check if the player has a Shirt and Pants and from there change those instead of putting new ones. This would look something like this:

Players = game:GetService('Players')
Teams = game:GetService('Teams')

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		humanoid:RemoveAccessories()
		task.wait()

		local team =  player.Team

		local hat =  team.Hat:Clone() 
		local shirt = team.Shirt
		local pants = team.Pants
		
		hat.Parent = character
		
		local playerShirtGraphic = character:FindFirstChildWhichIsA("ShirtGraphic")
		if playerShirtGraphic then
			playerShirtGraphic:Destroy()
		end
		
		local playerShirt = character:FindFirstChildWhichIsA("Shirt")
		if playerShirt then
			playerShirt.ShirtTemplate = shirt.ShirtTemplate
		else
			playerShirt = pants:Clone()
			playerShirt.Parent = character
		end
		
		local playerPants = character:FindFirstChildWhichIsA("Pants")
		if playerPants then
			playerPants.PantsTemplate = shirt.PantsTemplate
		else
			playerPants = pants:Clone()
			playerPants.Parent = character
		end
	end)
end)

I haven’t tested the above, but it should work. If you don’t want to do this, then you could also settle with a pre-defined HumanoidDescription and applying that instead.

1 Like
Players = game:GetService('Players')
Teams = game:GetService('Teams')

Players.PlayerAdded:Connect(function(player)
	player.CharacterAppearanceLoaded:Connect(function(character)
		local humanoid = character:WaitForChild("Humanoid")
		humanoid:RemoveAccessories()
		
		if character:FindFirstChild("Shirt") then
			character:FindFirstChild("Shirt"):Destroy()
		end
		
		if character:FindFirstChild("Pants") then
			character:FindFirstChild("Pants"):Destroy()
		end
		
		if character:FindFirstChild("Shirt Graphic") then
			character:FindFirstChild("Shirt Graphic"):Destroy()
		end
		
		task.wait(3)
		local team = player.Team
		local hat = team.Hat:Clone() 
		local shirt = team.Shirt:Clone()
		local pants = team.Pants:Clone()
		shirt.Parent = character
		pants.Parent = character
		hat.Parent = character
	end)
end)
2 Likes

Would probably be best to replace wait() with task.wait() also I think it would be better to clone from the original clothing instances as opposed to modifying the template properties of any existing clothing instances belonging to the player’s character model.

1 Like

I was not aware of what task.wait() was. Also, I don’t think it makes a difference to delete it. I personally like keeping it in the case that something in between breaks and causes the script to stop, so it doesn’t just have the player naked. Also, I don’t know if it affects performance much, but I am not creating a new instance, just editing it, so the game doesn’t have to worry about creating another instance. To be fair though, I guess an easier way to do mass-editing per team would be applying a HumanoidDescription. Either way, both scripts work.

1 Like