I want to make a script that gives you a hat if you join a certain team e.g. the Security Department. I have put the script in game.ServerScriptService. When you switch to the Security Team, it clones the hat into your character however it does not get rid of the characters current accessories e.g. their hair, glasses, backpacks etc...
Here is my code:
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
if plr.TeamColor == game.Teams["Security Dept."].TeamColor then
for i,v in pairs(char:GetChildren()) do --this is the hat remover part
if v.ClassName == "Accessory" then
v:Destroy()
end
end
-- this is the hat giver below
game.ServerStorage.SecurityHat:Clone().Parent = char
end
end)
end)
Should I put the script in a different place or make it a local script or is there something wrong with the hat giver?

1 comment
Hmm, it gives me the hat but it doesn't remove my hair and glasses.