How to Make an E-Key Sliding Door in Roblox Studio
Posted: Sat Jul 25, 2026 12:51 pm
How to Make an E-Key Sliding Door in Roblox Studio
Create an anchored Part named Door in Workspace. Add an Attachment named PromptAttachment to the door, place a ProximityPrompt inside the Attachment, and add a Script directly under the door.
Configure the ProximityPrompt
Configure the ProximityPrompt:
Use the Attachment's Position property to place the interaction point on the door. Roblox supports ProximityPrompt objects under Attachments, BaseParts, and Models whose PrimaryPart is set. The default keyboard key is E, but setting it explicitly makes the intended control clear. Setting HoldDuration to 0 makes the action trigger immediately when the input is pressed.
Add the server script
Paste this code into the Script:
Test and adjust the slide direction
Test the door in Play mode. If it needs to slide in the opposite direction, subtract the direction vector instead:
MaxActivationDistance controls the maximum distance at which the prompt appears for a player's character. The Triggered event supplies the Player who completed the interaction. TweenService:Create() accepts the instance to animate, a TweenInfo, and a table containing target property values. Here it animates the anchored door's Position, while CFrame.RightVector determines the door's local rightward direction.
Sources and verification
Create an anchored Part named Door in Workspace. Add an Attachment named PromptAttachment to the door, place a ProximityPrompt inside the Attachment, and add a Script directly under the door.
Code: Select all
Workspace
└── Door (Part)
├── PromptAttachment (Attachment)
│ └── ProximityPrompt
└── ScriptConfigure the ProximityPrompt:
| Property | Value |
|---|---|
| ObjectText | Door |
| ActionText | Open |
| KeyboardKeyCode | E |
| MaxActivationDistance | 10 |
| HoldDuration | 0 |
Add the server script
Paste this code into the Script:
Code: Select all
local TweenService = game:GetService("TweenService")
local door = script.Parent
local attachment = door:WaitForChild("PromptAttachment")
local prompt = attachment:WaitForChild("ProximityPrompt")
local closedPosition = door.Position
local openPosition = closedPosition + door.CFrame.RightVector * (door.Size.X + 1)
local tweenInfo = TweenInfo.new(1, Enum.EasingStyle.Quad, Enum.EasingDirection.Out)
local isOpen = false
local busy = false
prompt.ActionText = "Open"
prompt.Triggered:Connect(function(_player)
if busy then
return
end
busy = true
local targetPosition = isOpen and closedPosition or openPosition
local tween = TweenService:Create(door, tweenInfo, {
Position = targetPosition,
})
tween:Play()
local playbackState = tween.Completed:Wait()
if playbackState == Enum.PlaybackState.Completed then
isOpen = not isOpen
prompt.ActionText = isOpen and "Close" or "Open"
end
busy = false
end)Test the door in Play mode. If it needs to slide in the opposite direction, subtract the direction vector instead:
Code: Select all
local openPosition = closedPosition - door.CFrame.RightVector * (door.Size.X + 1)Sources and verification
- Proximity prompts — Documents supported prompt parents, positioning prompts with Attachments, prompt text and input properties, activation distance, and zero-duration input behavior.
- ProximityPrompt — Documents the default E keyboard key, supported parents, text properties, activation distance, and the Player parameter supplied by Triggered.
- TweenService — Documents TweenService:Create and demonstrates tweening the Position of an anchored Part.
- CFrame — Documents orientation-derived CFrame vectors, including RightVector.