Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Team hat code not working? [ANSWERED]

Asked by 8 years ago

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

Log in to vote
0
Answered by
xAtom_ik 574 Moderation Voter
8 years ago

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)

0
Thank you, I can't believe I overlooked that. It works perfectly now :) BartyCrouchJunior 57 — 8y
0
What about face(hat) and hair? Rdumb1 4 — 5y
Ad

Answer this question