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

How do you change a parts color if you touch another part?

Asked by 1 year ago

When you touch the scripts parent, a object in the workspace should change color and then unanchor and create an explosion. It cant get to the explosion because it won't change color. How do I make it change color?

script.Parent.Touched:Connect(function()
    script.Parent.Parent.Parent.Parent.ff.BrickColor(255,0,0)
    wait(3)
    script.Parent.Parent.Parent.Parent.ff.Anchored = false
    local explosion = Instance.new("Explosion")
    explosion.Position = script.Parent.Parent.Parent.Parent.ff.Position
    explosion.Parent = game.Workspace
end)

1 answer

Log in to vote
1
Answered by 1 year ago
Edited 1 year ago

You aren't using BrickColor correctly. You should be using BrickColor.new, but in this case you want RGB. You should use Color3.fromRGB instead.

Code example:

script.Parent.Touched:Connect(function()
    script.Parent.Parent.Parent.Parent.ff.Color = Color3.fromRGB(255,0,0)
    wait(3)
    script.Parent.Parent.Parent.Parent.ff.Anchored = false
    local explosion = Instance.new("Explosion")
    explosion.Position = script.Parent.Parent.Parent.Parent.ff.Position
    explosion.Parent = game.Workspace
end)

This code has not been tested prior to response there may be other issues covered by other answers.

Hope this helps!

Ad

Answer this question