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

If part is a color then?

Asked by 5 years ago

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?

0
It should be == BrickColor.new("Bright green") fredfishy 833 — 5y

2 answers

Log in to vote
1
Answered by
Zafirua 1348 Badge of Merit Moderation Voter
5 years ago
Edited 5 years ago

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.

Ad
Log in to vote
0
Answered by
Launderer 343 Moderation Voter
5 years ago
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

0
does not work ElusiveEpix 2 — 5y

Answer this question