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

Make a brick change it's color after clicking two buttons?

I want to make a door that will only open after you clicked two buttons but I can't seem to make it work.

Here is the script:

--Button1 Script with click detector
function onClicked(Button1)
	script.Parent.BrickColor = BrickColor.new("Bright green")
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
--Button2 Script with click detector
function onClicked(Button2)
	script.Parent.BrickColor = BrickColor.new("Bright green")
end
script.Parent.ClickDetector.MouseClick:connect(onClicked)
--Exit Script
local button1 = game.Workspace.Button1
local button2 = game.Workspace.Button2
if button1 and button2 == BrickColor("Bright green") then
	function sign(Exit)
		script.Parent.BrickColor = BrickColor.new("Bright green")
	end
end

I don't know how to do this... I can get the Button1 and Button2 working but not the Exit sign.

P.S. I'm only a newbie in scripting.

1 answer

✓ Accepted answer

Alright, let's clean up that code a bit. First off, let's merge everything into one script to keep everything organized -- this also makes it easier to keep track of when buttons are pushed.

local button1 = workspace.Button1
local button2 = workspace.Button2
local door = workspace.Door
--You can use just "workspace" instead of "game.Workspace"; it's much neater, so I prefer it

local isButton1Clicked = false
local isButton2Clicked = false
--Will use to track if the buttons are pressed or not

local debounce = false
function checkButtons()
	if debounce == false and isButton1Clicked == true and isButton2Clicked == true then
		--Debounce prevents players from spam-clicking buttons and having this run more times than it needs to be
		debounce = true
		door.Transparency = 1
		door.CanCollide = false

		wait(4)

		door.Transparency = 0
		door.CanCollide = true
		button1.BrickColor = BrickColor.new("Bright red")
		button2.BrickColor = BrickColor.new("Bright red")
		isButton1Clicked = false
		isButton2Clicked = false
		debounce = false--Allow players to use the door again	
	end
end

button1.ClickDetector.MouseClick:connect(function()
	isButton1Clicked = true
	button1.BrickColor = BrickColor.new("Bright green")
	checkButtons()
end)

button2.ClickDetector.MouseClick:connect(function()
	isButton2Clicked = true
	button2.BrickColor = BrickColor.new("Bright green")
	checkButtons()
end)

1 comment

0

Thank you! I'm going to test these ASAP... can't right now because I'm really busy. Thanks again!

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