Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

4 comments

1

You forgot a = in the if statement, just saying.

0

Updated the question, please re-read it because there's another problem

0

Ah, yes. You are correct. He missed a conditional operator as well. Thanks.

0

Try it now, I have updated the answer @LogicIntel

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

This discussion is preserved as it was. New answers, comments, and votes are closed.