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

How do you change a model's color?

Asked by 8 years ago

Sorry if I'm bad at explaining.

This is my script.

function onTouched(hit)
    script.Parent.Parent.ARGH.Transparency = 1
    script.Parent.Parent.ARGH.CanCollide= true
    wait(7.5)
    script.Parent.Parent.ARGH.Transparency= 1 
    script.Parent.Parent.ARGH.CanCollide= false
end
script.Parent.Touched:connect(onTouched)

After pressing the button, it should change the platform's color. After 7.5 seconds, it goes back to its original color.

I tried something like this to change its color.

script.Parent.Parent.Lite.Lite1.BrickColor = BrickColor.new(Color3.new(1, 1, 1))

However, it didn't work. I couldn't use union, because it says "unsolvable".

Any solutions? (Once again, sorry if it's too hard to understand, I'm really bad at explaining)

2 answers

Log in to vote
1
Answered by 8 years ago
model = game.Workspace.Model

for i,v in pairs(model:GetChildren())  do -- iterates through the children of the model
if v:IsA("Part") then--if its a part
v.BrickColor = BrickColor.new(Color1.new(1,1,1))--changes color
end
end
2
TAB YUR SCRAPT!!!!1111!!111 NotSoNorm 777 — 8y
Ad
Log in to vote
-2
Answered by
hiccup111 231 Moderation Voter
8 years ago

This version may seem a little long-winded, but basically when it fires, it will:

  1. Set a debounce ( so the funciton only fires once at a time ).

  2. Get a new - random colour for the model change into (You can set this colour to anything you want)).

  3. Scan through the model for Parts.

3.1. Get the part's original colour, and make a copy of it (using a BrickColorValue).

3.2. Change the part's colour.

  1. Wait 7.5 seconds.

  2. Scan through the model for Parts again. 5.1. Change part's colour to original BrickColorValue.

  3. Return Debounce to false.

local model = Workspace.Model -- Change path if neccesarry.

function onTouched(hit)
    --1.
     if debounce then return end
    debounce = true

    --2.
    local newColour = BrickColor.Random()

    --3.
    for _,part in pairs(model:GetChildren()) do
        if part:IsA("BasePart") or part:IsA("UnionOperation") then
            --3.1.
            local bc = part:FindFirstChild("OriginalBrickColor") or Instance.new("BrickColorValue",part)
            bc.Name = "OriginalBrickColor"
            bc.Value = part.BrickColor

            --3.2.
            part.BrickColor = newColour
        end
    end

    --4
    wait(7.5)

    --5
    for _,part in pairs(model:GetChildren()) do
        if part:IsA("BasePart") or part:IsA("UnionOperation") then
            if part:FindFirstChild("OriginalBrickColor") then -- just incase. =]
                --5.1.
                part.BrickColor = part.OriginalBrickColor.Value
            end
        end
    end

    --6
    debounce = false
end
script.Parent.Touched:connect(onTouched)

0
Sorry about the paragraph positioning, something messed up with it, and I can't get it straight ;3 hiccup111 231 — 8y

Answer this question