Skinstashery
Roblox
Home / Roblox / Studio script library / Proximity prompt door
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

  1. Insert a Part for the door and set Anchored to true.
  2. Add a Script inside the Part and paste the code.
  3. Play and walk up to the door. A small prompt with a key shows up.
  4. Press the key (E on a keyboard) to open the door. Press it again to close.

Change it

More in Doors and interaction

All Roblox scripts

More Roblox tools