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

How Can I Turn A Model The Color Of A Player's Team With A Button?

Asked by
jacobwow 140
10 years ago

I have a script that turns a model orange and if I press it again it turns teal. But I just want to turn the color of the model to the player's team! Script:

var1 = true
function onTouch(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid")
    if humanoid ~= nil then
        if var1 == true then
            wait(.5)
            for i, v in pairs(game.Workspace.Base2:GetChildren()) do
                v.BrickColor = BrickColor.new("Bright orange") --Whatever color you want it to change inside the parenthesis
            end
            var1 = false
        elseif var1 == false then
            wait(.5)
            for i, v in pairs(game.Workspace.Base2:GetChildren()) do
                v.BrickColor = BrickColor.new("Bright bluish green") --Whatever color you want it to change second inside the parenthesis
            end
            var1 = true
        end
    end
end
script.Parent.Touched:connect(onTouch)

1 answer

Log in to vote
1
Answered by
Ekkoh 635 Moderation Voter
10 years ago

I'd retrieve the TeamColor by getting the Player through the Character that touches it.

var1 = true
function onTouch(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid")
    if humanoid ~= nil then
        if var1 == true then
        local tColor = Game:GetService("Players"):GetPlayerFromCharacter(part.Parent).TeamColor
        print("tColor: " .. tColor.Name)
            wait(.5)
            for i, v in pairs(game.Workspace.Base2:GetChildren()) do
                v.BrickColor = tColor --Whatever color you want it to change inside the parenthesis
            end
            var1 = false
        elseif var1 == false then
            wait(.5)
            for i, v in pairs(game.Workspace.Base2:GetChildren()) do
                v.BrickColor = tColor --I'm not sure if you wanted to change both to the team color?
            end
            var1 = true
        end
    end
end
script.Parent.Touched:connect(onTouch)
Ad

Answer this question