I am adding buttons in my game that you can press which turn the button and screens red to indicate they were pressed. When all buttons are pressed, it should open a secret door and play a sound of the door opening. But when I tested it once I had pressed all the buttons the secret door did not open, is there anything wrong with the code?
if game.Workspace.Screen1.BrickColor == BrickColor.new("Really red") then if game.Workspace.Screen2.BrickColor == BrickColor.new("Really red") then if game.Workspace.Screen3.BrickColor == BrickColor.new("Really red") then script.Parent.evad:Play() wait(2) script.Parent:Destroy() end end end
The script detects if the screens are red (on) and then destroys itself after making the door opening noise. Evad is the sound of the door opening.
I assume that unlike in R4INBOWDASH's answer, your doors aren't red when the game just starts. You are only checking if the doors are red once, when the game just loads. What you should really do is to keep on checking them. You can do this while using a repeat - until
loop.
Here is the fixed script:
local checked = false --We are defining a boolean here to make sure we didn't already check it. repeat wait() if game.Workspace.Screen1.BrickColor == BrickColor.new("Really red") then if game.Workspace.Screen2.BrickColor == BrickColor.new("Really red") then if game.Workspace.Screen3.BrickColor == BrickColor.new("Really red") then if not checked then --Checking if we didn't already check. script.Parent.evad:Play() wait(2) script.Parent:Destroy() end until game.Workspace.Screen1.BrickColor == BrickColor.new("Really red") and game.Workspace.Screen2.BrickColor == BrickColor.new("Really red") and game.Workspace.Screen3.BrickColor == BrickColor.new("Really red") and game.Workspace.Screen4.BrickColor == BrickColor.new("Really red") --Will stop when the conditions are met. end end end
Hope this helps!!
Don't forget to accept this if it does!!!
I'm assuming that the issue was the ifs. It worked for me when I did this:
if game.Workspace.Screen1.BrickColor == BrickColor.new("Really red") and game.Workspace.Screen2.BrickColor == BrickColor.new("Really red") and game.Workspace.Screen3.BrickColor == BrickColor.new("Really red") then script.Parent.evad:Play() wait(2) script.Parent:Destroy() end
the sound played and the parent got destroyed! Please accept my answer if it works. If it doesn't, please let me know
You could just have a value that is incremented when each button is pressed And if one deactivated decrement it. Then have a .Changed listener on the value and if it hits 3 then open the door.