How to Make a Working Door Inside of Roblox Studio

Hello and welcome to today’s tutorial. Today I will be showing you how to make 2 types of doors. A door that automatically closes after a set amount of time and a door that has to be opened and closed by you manually. Let’s get started!

1. Make the Door
The main parts that we are going to need are a button and the door. You can add walls around it to look fancy and all but they are not part of the code so no need to worry about them. Make sure you name your parts so you can reference them later in the script. In my example I’ll name them “Door” & “Button”

2. Scripting the Button to be Automatic
Add a script inside of the Button and write this script:

local Door = game.Workspace.Door -- Type the name of your door
local Button = script.Parent
Button.BrickColor = BrickColor.new("Really red") -- Makes the button red (DELETE IF YOUR PART IS ALREADY RED FROM THE PROPERTIES)

Button.RedDetector.MouseClick:Connect(function()
	
	Door.CanCollide = false -- Sets Can Colide to false so the player can walk through the part
	Door.BrickColor = BrickColor.new("Lime green") -- Changes the button color to lime greem
	Door.Transparency = 1 -- Makes the Part Invisable
	Door.Anchored = true -- Ensures the door is anchored
	
	wait(3)  -- edit this to how much time you want the door to be opened for
	
	Door.CanCollide = true -- Makes it so you cant walk through the door
	Door.BrickColor = BrickColor.new("Really red") -- Makes the button red again after time is up
	Door.Transparency = 0 -- Makes the door visable
	
	
end)

3. Scripting the Button to be Manual
Add a script inside of the Button and write this script:

local Door = game.Workspace.Door -- Type the name of your door
local Button = script.Parent
local debounce = false
Button.BrickColor = BrickColor.new("Really red") -- Makes the button red (DELETE IF YOUR PART IS ALREADY RED FROM THE PROPERTIES)

Button.RedDetector.MouseClick:Connect(function()
	if debounce == false then -- When you click the button turns green and the door opens
		
		wait(0.3)
		
		debounce = true
		Door.Transparency = 1 -- sets the door to unvisible
		Door.CanCollide = false -- makes the door so you can walk through
		Button.BrickColor = BrickColor.new("Lime green")
		
		Door.Anchored = true -- Ensures the door is anchored
	else -- When clicked again make the buton red ad close the door
		
		wait(0.3) -- Waiting tim einbetween to prevent spaming
		
		debounce = false
		Door.Transparency = 0 -- Make the door visible
		Door.CanCollide = true -- Makes the door so you can't walk through it
		Button.BrickColor = BrickColor.new("Really red") -- Set the bricks color
	end

end)

Thank you very much for coming by I hope this tutorial helped you!

5 Likes

You’d need to use Player:GetRankInGroup() for that.

2 Likes