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

If part is a color then?

Hello, I wanted to make buttons like the ones in flood escape 2, but I couldn't figure out how to make an if statement if a part is a certain color. Here is the code I have:

if game.Workspace.Interactives._Button2.Light.BrickColor == ("Bright green") then
game.Workspace.Interactives._Button1.Hitbox.Touched:Connect(function()
	game.Workspace.Interactives._Button1.Light.BrickColor = BrickColor.new("Bright red")
	game.Workspace.Interactives._Button1.Hitbox:Destroy()
	game.Workspace.Interactives._Button2.Light.BrickColor = BrickColor.new("Bright green")
	print("Button 2 pressed!")
end)
end

So basically if you press button 1 it destroys the hitbox and then button 2 turns green, but its only supposed to work when button 2 is green to activate it, but button 2 doesn't activate at all. Please help?

1 comment

0

It should be == BrickColor.new("Bright green")

2 answers

✓ Accepted answer

When you are checking for a Part's properties or anything, you do not want to use a single string just to check for it.

In your example, you did.

if game.Workspace.Interactives._Button2.Light.BrickColor == ("Bright green") then 

when it should be

if game.Workspace.Interactives._Button2.Light.BrickColor == BrickColor.new("Bright green") then

That is a really long if statement. Consider creating a variable instead.

-- [Declaration Section]
local Workspace = game:GetService("Workspace");
local Light = Workspace.Interactives._Button2;

-- [Output Section]
if Light.BrickColor == BrickColor.new("Bright green") then
	--Do Stuff
end;

If this does not work, then you definitely have some other errors. Post your errors and I will fix it for you. Accept the answer if it did help so we can both earn some points.

if game.Workspace.Interactives._Button2.Light.BrickColor == BrickColor.new("Bright green") then
2	game.Workspace.Interactives._Button1.Hitbox.Touched:Connect(function()
3	    game.Workspace.Interactives._Button1.Light.BrickColor = BrickColor.new("Bright red")
4	    game.Workspace.Interactives._Button1.Hitbox:Destroy()
5	    game.Workspace.Interactives._Button2.Light.BrickColor = BrickColor.new("Bright green")
6	    print("Button 2 pressed!")
7	end)
8	end

1 comment

0

does not work

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