I've asked this question twice before, got some feedback and edited my script only to find that it still isn't working. It is supposed to give players a hat depending on what team they're on. Here is my code:
game.Players.PlayerAdded:connect(function(Plr) Plr.CharacterAdded:connect(function(Char) local Contents = Char:GetChildren() for _, v in pairs(Contents) -- Remove all existing hats to add new one(s) if v:IsA("Hat") then v:remove() end end if Plr.TeamColor == BrickColor.new("Bright blue") then -- Check the team Color local Hat1 = game.ServerStorage.Hat1:Clone() Hat1.Parent = Char elseif Plr.TeamColor == BrickColor.new("Bright red") then local Hat2 = game.ServerStorage.Hat2:Clone() Hat2.Parent = Char end end) end)
I edited a little and got the following script working
game.Players.PlayerAdded:connect(function(Plr) Plr.CharacterAdded:connect(function(Char) wait(0.5) -- Wait so that the hats load local Contents = Char:GetChildren() for _, v in pairs(Contents) do -- "You missed the 'do'" Remove all existing hats to add new one(s) if v:IsA("Hat") then v:remove() end end if Plr.TeamColor == BrickColor.new("Bright blue") then -- Check the team Color local Hat1 = game.ServerStorage.Hat1:Clone() Hat1.Parent = Char elseif Plr.TeamColor == BrickColor.new("Bright red") then local Hat2 = game.ServerStorage.Hat2:Clone() Hat2.Parent = Char end end) end)