Skinstashery
Roblox
Home / Roblox / Studio script library / Click door
RB-004

Roblox click door script

A door that opens when a player clicks it and closes again by itself.

Script type
Script
Where it goes
Inside the door Part
Category
Doors and interaction

For your own game in Roblox Studio. Not for use in other people's games.

The code

-- Click door: click the part to open it. It closes after a few seconds.

local OPEN_TIME = 3          -- seconds the door stays open
local OPEN_TRANSPARENCY = 0.7
local MAX_CLICK_DISTANCE = 12

local door = script.Parent

local detector = door:FindFirstChildOfClass("ClickDetector")
if not detector then
	detector = Instance.new("ClickDetector")
	detector.Parent = door
end
detector.MaxActivationDistance = MAX_CLICK_DISTANCE

local isOpen = false

detector.MouseClick:Connect(function(player)
	if isOpen then
		return
	end
	isOpen = true

	door.CanCollide = false
	door.Transparency = OPEN_TRANSPARENCY

	task.wait(OPEN_TIME)

	door.CanCollide = true
	door.Transparency = 0
	isOpen = false
end)

How to set it up

  1. Insert a Part and make it look like a door. Set Anchored to true.
  2. Add a Script inside the door Part.
  3. Paste the code. The script adds the ClickDetector for you.
  4. Play, walk up to the door and click it.

Change it

More in Doors and interaction

All Roblox scripts

More Roblox tools