Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Team hat code not working? [ANSWERED]

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)

1 answer

✓ Accepted answer

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)

2 comments

0

Thank you, I can't believe I overlooked that. It works perfectly now :)

0

What about face(hat) and hair?

This discussion is preserved as it was. New answers, comments, and votes are closed.