New: Nitro Boost our Discord server and receive full donation perks here on the website! Join the Scripting Helpers Discord Server to learn more! You can also Support on Patreon as always.
Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

What is wrong with this..?

Asked by 3 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

Script idea if player is on team then change brickcolor and material

Everything works but it always turns White even if I am on the Dark team. Any fixes?

local white = ("Institutional white")
local black = ("Really black")
local teams = game.Teams:GetTeams()



script.Parent.Touched:connect(function(hit)
    player = game.Players:GetPlayerFromCharacter(hit.Parent)
    if player then
        hey = player.TeamColor
        for idx = 1, #teams do
            local team = teams[idx]
            if team.Name == "Light" then
                script.Parent.BrickColor = BrickColor.new(white)
                script.Parent.Material = "Neon"
                break
            end
            if team.Name == "Dark" then             
                script.Parent.BrickColor = BrickColor.new(black)
                script.Parent.Material = "Neon"
                break
            end
        end
    end
end)

1 answer

Log in to vote
1
Answered by
RedCombee 585 Moderation Voter
3 years ago

You never actually check to see what team the player is on. Rather, you just iterate the table, and every time the if statement is run, you break the function. Instead, you need to check the player's team color.

teams = game:GetService("Teams"):GetTeams()
script.Parent.Touched:connect(function(hit)
    player = game.Players:GetPlayerFromCharacter(hit.Parent)
        if player then
            for i = 1, #teams do
                team = teams[i]
                if team.TeamColor = player.TeamColor then
                    script.Parent.BrickColor = BrickColor.new(team.TeamColor)
                    script.Parent.Material = "Neon"
                end
            end
        end
    end
end)
Ad

Answer this question