RB-004
Roblox proximity prompt door script
A door that opens when a player walks up and presses the prompt key.
- 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
-- Proximity prompt door: press E near the door to open or close it.
local ACTION_TEXT_OPEN = "Open"
local ACTION_TEXT_CLOSE = "Close"
local OBJECT_TEXT = "Door"
local HOLD_DURATION = 0 -- seconds to hold the key; 0 means a tap
local MAX_DISTANCE = 10
local door = script.Parent
local prompt = door:FindFirstChildOfClass("ProximityPrompt")
if not prompt then
prompt = Instance.new("ProximityPrompt")
prompt.Parent = door
end
prompt.ObjectText = OBJECT_TEXT
prompt.ActionText = ACTION_TEXT_OPEN
prompt.HoldDuration = HOLD_DURATION
prompt.MaxActivationDistance = MAX_DISTANCE
local isOpen = false
prompt.Triggered:Connect(function(player)
isOpen = not isOpen
door.CanCollide = not isOpen
door.Transparency = if isOpen then 0.7 else 0
prompt.ActionText = if isOpen then ACTION_TEXT_CLOSE else ACTION_TEXT_OPEN
end)How to set it up
- Insert a Part for the door and set Anchored to true.
- Add a Script inside the Part and paste the code.
- Play and walk up to the door. A small prompt with a key shows up.
- Press the key (E on a keyboard) to open the door. Press it again to close.
Change it
- Set HOLD_DURATION to 1 if you want the player to hold the key.
- Prompts work on phones and game controllers too, which is why they beat click detectors for new games.
- To make a door that closes by itself, add a task.wait and set the door back after the prompt fires.
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.