Making A Multiple Button System

Hey, Roblox Developer Community! I’m currently creating my first video game and I wanted to ask for some help on creating a multiple button system. The Goal of the script is for the server to detect when all three buttons are pressed, a bridge would be created inside the client. Here is the model I have created as an example.

Here is where the buttons are stored.

image

The Script is stored inside the server script service,
image

This is the script I have created. It will detect when any of the three buttons are touched, but only if it is a humanoid.

This is what it looks like when it is in action and working.
robloxapp-20211106-1133161.wmv (3.2 MB)

As you can see, if only one button is pressed, the bridge will appear. However, I want my script to make it so that only if all three of the buttons are pressed, then the bridge will appear. I’m unsure of how to script this, So I’m reaching out for some assistance.

What I’d do is, make a Value inside each button.
As soon as one Button is touched it’ll set the value to true and check if the other buttons have their value as true, if they do then it’ll do the Bridge, if they don’t then nothing will happen.
Haven’t been able to checkout the file so sorry if this is unneeded information!

Not the most efficient but here’s a working fix :slight_smile:

add a NumberValue to the ButtonsFolder and set its value to 0

when the button is pressed once, set the value of it to +1

when it’s reaching 3, make the bridge visible

You can do that by doing

workspace.ButtonsFolder.YourValueHere.Changed:Connect(function()
 if YourValueHere.Value == 3 then
-- do your stuff here
end
end)
4 Likes

Yes! Your advice worked, I have successfully made the script detect all three buttons.

1 Like

Great! Wish you the best of luck in making your game!

You could also achieve the same result with just a variable in the script itself.

local buttonPresses = 0

--code which handles a button press
buttonPresses += 1
if buttonPresses == 3 then
	--all 3 buttons pressed
else --not all buttons pressed
	--do stuff
end