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

Can I have help with this Part Changer?

local ChangePart = game.Workspace.Part

if ChangePart.BrickColor == BrickColor.Red() then
	ChangePart.BrickColor = BrickColor.Yellow()
or
	ChangePart.BrickColor == BrickColor.Green()
end

I need help with this please, I want it so if it is red, it will change to yellow, or if it is not red it will change to green, please help. xD

1 comment

0

I see that error and another one on line 5. Or should be else.

3 answers

✓ Accepted answer

You've got two errors in your script. The first one is that you are using or in the wrong place. In an if statement, you need else if you want to do something if the condition of the if statement isn't true.

Secondly, you only need one equals sign on line 6. One equals sign = is for assigning values and two equals signs == is for comparing values, such as your condition in line 3.

Your script should look like this when you fix both of these errors:

local ChangePart = game.Workspace.Part

if ChangePart.BrickColor == BrickColor.Red() then
	ChangePart.BrickColor = BrickColor.Yellow()
else --Else is used if the condition above is not met.
	ChangePart.BrickColor = BrickColor.Green() --One = sign for assigning values, two = signs for comparing values.
end

I hope this helped you. If my answer helped, be sure to accept it. :)

Link for conditional statements.

Link for the list of operators you can use.

2 comments

0

Thank you! This has helped me in my game!

0

You're welcome. Be sure to accept my answer, it's the tick button to the left.

You have two errors.

The first being that you need to replace or with else. Else is for if statements.

The second being that you used two equals signs (==) on line 6 when you should have only used one.

Here's the fixed script.

local ChangePart = game.Workspace.Part

if ChangePart.BrickColor == BrickColor.Red() then
    ChangePart.BrickColor = BrickColor.Yellow()
else
    ChangePart.BrickColor = BrickColor.Green()
end

Hope this helped.

If there's more than one part in workspace, I suggest renaming that part.

1 comment

0

Yep! That helped! Thank you for the answer!

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