Door that is opened after pressing buttons

Hi, I’m trying to figure out make a door in Roblox studio that is opened by pressing buttons in an order.
Like after one button is pressed another button has to be pressed to open the door how do I make this?
(First post/topic sorry if short)

1 Like

You can add a table in a main server script that handles this, for example

local table = {}

for i,v in pairs(workspace.ButtonsFolder:GetChildren()) do
v.ClickDectector.MouseClick(not sure if this is correct):Connect(function()
table.insert(table,v.Name)
end)

Here, it is creating a table, then it loops through the buttons folder and sees which one is clicked, then it adds it to that table. Then you can add another script that checks that table or something.

Ofcourse, it may be better if you looked at a free models script to better understand how to do this.

1 Like

Not trying to be rude, but can you move this topic to scripting support category?

This is one of my old, uncopylocked places which features a keycode door that works by requiring a ModuleScript.

Hope this helps.

1 Like

Make two parts with the name “PartThatIsAButtonForDoor” and place it in the Workspace. Place the parts of the door inside of a Folder in Workspace, You can place other parts that look like the two parts for PartThatIsAButtonFordoor around it for a riddle puzzle sort of thing. These two parts are the ones you want to click for the door to ‘open’ which sets the door’s (every part in that folder) transparency to 1, which is invisible.

-- lets declare the starting number so we can track how much times its clicked after
local partsClicked = 0

-- lets create a function that keeps track of the part that is being clicked
function onPartClicked(part)
  -- Check if the part is named "PartThatIsAButtonForDoor"
  if part.Name == "PartThatIsAButtonForDoor" then
    -- Increment the partsClicked variable
    partsClicked = partsClicked + 1
  end
  
  -- lets check if both of these parts with the same name have been clicked 
  if partsClicked == 2 then
    -- Set the parts in the folder to 1
    for _, part in pairs(game.Workspace.Folder:GetChildren()) do
      part.Transparency = 1
    end
  end
end

-- the click event for the onPartClicked function
for _, part in pairs(game.Workspace:GetDescendants()) do
  if part:IsA("BasePart") then
    part.Click:Connect(onPartClicked)
  end
end

This script lets you click two correct buttons in a gui instead of parts

local button1Clicked = false
local button2Clicked = false

-- button 1 being clicked
local function onButton1Clicked()
    button1Clicked = true
    checkIfBothButtonsClicked()
end

-- for button 2 being clicked
local function onButton2Clicked()
    button2Clicked = true
    checkIfBothButtonsClicked()
end

-- checks if both buttons are clicked
local function checkIfBothButtonsClicked()
    if button1Clicked and button2Clicked then
        -- set the parts of the folder to 1
        local folder = game.Workspace:FindFirstChild("Folder")
        if folder then
            folder.Part1.Transparency = 1
            folder.Part2.Transparency = 1
        end
    end
end

-- click event for functions
local button1 = game.Workspace.Gui:FindFirstChild("GuiButtonToOpenDoor1")
if button1 then
    button1.MouseButton1Click:Connect(onButton1Clicked)
end

local button2 = game.Workspace.Gui:FindFirstChild("GuiButtonToOpenDoor2")
if button2 then
    button2.MouseButton1Click:Connect(onButton2Clicked)
end

not sure if this is still open, but maybe try using some if and then if statements

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.