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

Does anybody know what's wrong with my 'if' Statement?

Well I understand a bit of Lua but I need help on this if statement.

function 
Game.Workspace.Part1 = P1
Game.Workspace.Part2 = P2

if P1 and P2 = new.Color("Bright red") then      --Here is my problem, how do you say color like this?
	Print("They are both red!")
end

Anyone know?

4 answers

✓ Accepted answer

Well number 1, you're using = instead of ==, number 2, the if statement is incorrect syntax, and number 3, new.Color isn't valid syntax. This is how it should be written:

local P1 = game.Workspace.Part1
local P2 = game.Workspace.Part2
if P1.BrickColor.Name == "Bright red" and P2.BrickColor.Name == "Bright red" then
	print("They are both red!")
end

Hope this helped!

*Note: if you still have trouble with using BrickColor, click here: BrickColor

2 comments

0

DUDE THANKYOU, THAT WORKED!

0

If you would know, how would I play music in it? If you know can you edit this?

P1 = Game.Workspace.Part1 
P2 = Game.Workspace.Part2 

if P1 == P1.BrickColor("Bright red") and P2 == P2.BrickColor("Bright red") then      --Here is my problem, how do you say color like this?
    Print("They are both red!")
end

This should fix it. But I don't exactly know if it will because of the 'colors'

Lol, I forgot that it can't be =, it has to be == :/

1 comment

0

It says: 'then' expected near '=' I'll try to understand that.

I don't know if it is supposed to be written like this, just try it out:

if P1 and P2 = BrickColor.new("Bright red") then

2 comments

0

Ok thanks I'll get back to you in a sec.

0

Ok then. If it doesn't work, at least I tried.

Hmm I have tryed all of them, It seems hard to do if statements with parts propertys.

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