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

How do you make a part change it's color using an "if" "then" statement?

Asked by 9 years ago
var1 = Instance.new("Part",workspace)
    var1.Position = Vector3.new(0,0,0)
        var1.Name = "Testing"
wait(3)
    var1.BrickColor = BrickColor.new("Really red")
        var1.Transparency = 0.7
        var1.Anchored = True
wait(5)
if game.Workspace.Testing.Anchored == true then
    game.Workspace.Testing.BrickColor = BrickColor.new("Black")
end

2 answers

Log in to vote
1
Answered by
Necrorave 560 Moderation Voter
9 years ago

You almost had it there in your if statement.

You actually had the way you do it earlier in your code.

var1 = Instance.new("Part",workspace)
    var1.Position = Vector3.new(0,0,0)
        var1.Name = "Testing"
wait(3)
    var1.BrickColor = BrickColor.new("Really red") -- Similar to this.
        var1.Transparency = 0.7
        var1.Anchored = true
if game.Workspace.Testing.Anchored == true then -- Missing a '='
    game.Workspace.Testing.BrickColor = BrickColor.new("Black") -- Added here
end

Let me know if that works, if not I will look into it further!

EDIT: Keep in mind the difference between = and ==. You would use = to assign something to a variable. You would use == to compare.

More info on Conditional Operators/Statements: http://wiki.roblox.com/index.php?title=Conditional_statement

More info on BrickColor: http://wiki.roblox.com/index.php?title=BrickColor

1
You forgot a = in the if statement, just saying. ISellCows 2 — 9y
0
Updated the question, please re-read it because there's another problem LogicIntel 35 — 9y
0
Ah, yes. You are correct. He missed a conditional operator as well. Thanks. Necrorave 560 — 9y
0
Try it now, I have updated the answer @LogicIntel Necrorave 560 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

For if statements, you need to use == not =. And on line 7(The anchored line), you used True when it's supposed to be true. Capitalization count's in Lua.

var1 = Instance.new("Part",workspace)
var1.Position = Vector3.new(0,0,0)
var1.Name = "Testing"
wait(3)
var1.BrickColor = BrickColor.new("Really red")
var1.Transparency = 0.7
var1.Anchored = true
if game.Workspace.Testing.Anchored == true then
    game.Workspace.Testing.BrickColor = BrickColor.new("Black")
end

Answer this question