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
- Insert a Part and make it look like a door. Set Anchored to true.
- Add a Script inside the door Part.
- Paste the code. The script adds the ClickDetector for you.
- Play, walk up to the door and click it.
Change it
- Change OPEN_TIME to keep the door open longer.
- If a player is standing in the doorway when it closes, they can get stuck. Make OPEN_TIME long enough to walk through.
- The cursor changes to a hand when you point at the door. You can change it with detector.CursorIcon.
More in Doors and interaction
More Roblox tools
- Shirt and pants templatesFree Roblox clothing templates to download: hoodies, jerseys, jeans, joggers and more.
- Robux tax calculatorWork out what you receive after the marketplace fee, or what to charge.
- Robux to USD calculatorConvert earned Robux to dollars at a DevEx rate you can edit.
- Shirt and pants template makerColour each panel of the 585×559 clothing template and download it.
- Username generatorGenerate usernames that fit the 3–20 character rule.