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

How do I make this door open based on a part's color?

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.

3 answers

✓ Accepted answer

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!!!

3 comments

0

Thank you! But at line 11 where it says until there is an error where the script expected end to close 'then' at line 7 but got until.

0

I edited my script! It should work now.

0

There was just a missing "end".

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

2 comments

0

I also forgot to put that you want to check the brick colors on the server to prevent exploits, and you should have this run when a button is pressed or using part.Changed

0

I might have been doing something wrong since the script worked for you but it did not work for me. Thank you though!

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.

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