Trying to make a script where when a player joins and is on a certain team, the hats they are currently wearing are removed THEN replaced with a new hat. This is what I have so far, I don't know how to insert a hat from the ROBLOX catalog and weld it onto the player's head
local teams = {"British Army"}
function isTeam(plr)
for _,v in pairs(teams) do
if game.Teams[v].TeamColor == plr.TeamColor then
return true
end
end
return false
end
game.Players.PlayerAdded:connect(function(np)
np.CharacterAdded:connect(function(nc)
if isTeam(np) then
nc.ChildAdded:connect(function(item)
if item:IsA("Accessory") then
item:Destroy()
end
end)
end
end)
end)
Thank you

1 comment
To remove hat: for i,v, in pairs(np:GetChildren()) do if v:IsA("Accessory") do v:Remove() end end