The modern way to let players interact with objects — a floating E prompt that works on every device, no ClickDetector needed.
ClickDetector only works with a mouse. ContextActionService is great for actions but doesn't show a floating prompt on the object. ProximityPrompt is the modern middle ground — a floating "E to interact" prompt that appears when a walks up to something, and works on keyboard, gamepad, and mobile equally.
Parent a ProximityPrompt to any BasePart:
local prompt = Instance.new("ProximityPrompt")
prompt.ActionText = "Open Shop"
prompt.ObjectText = "Merchant"
prompt.HoldDuration = 0 -- instant tap, no holding
prompt.Parent = shopPart
ActionText — the action label ("Open Shop", "Pick Up", "Talk")ObjectText — what the prompt is attached to ("Merchant", "Chest", "Door")HoldDuration — how long the must hold the key (0 = instant)When a gets close, a floating prompt appears. They press E (keyboard), the button (mobile), or the face button (gamepad) to trigger it.
To make a ProximityPrompt require holding the key for 2 seconds, set HoldDuration to .
ProximityPrompt fires Triggered when the completes the interaction:
prompt.Triggered:Connect(function(player)
print(player.Name .. " opened the shop!")
-- open the shop GUI, give an item, etc.
end)
The callback receives the who triggered it — no need to look it up yourself.
For hold-to-interact (like channeling a heal), use HoldDuration > 0 and the Triggered fires when the hold completes:
prompt.HoldDuration = 3 -- hold for 3 seconds
prompt.Triggered:Connect(function(player)
-- heal complete
player.Character.Humanoid.Health = player.Character.Humanoid.MaxHealth
end)
You can also listen to TriggeredEnded if the releases early — useful for canceling a channel.
ProximityPrompts have several visual settings:
prompt.KeyboardKeyCode = Enum.KeyCode.E -- which key (default: E)
prompt.GamepadKeyCode = Enum.KeyCode.ButtonX -- which gamepad button
prompt.MaxActivationDistance = 10 -- how far away it works (studs)
prompt.RequiresLineOfSight = false -- true = must see the part
prompt.Enabled = false -- hide it
MaxActivationDistance controls the bubble around the where the prompt appears. Default is 10 studs — roughly 3 character heights.
RequiresLineOfSight = true means walls block the prompt. Good for locked doors, bad for shop NPCs.
Each interaction method has a sweet spot:
| Method | Best for | Limitation |
|---|---|---|
| ProximityPrompt | In-world objects (doors, NPCs, chests) | Attached to a part |
| ClickDetector | Legacy click-to-interact | Mouse only, no gamepad |
| ContextActionService | Global actions (jump, sprint, inventory) | No floating prompt |
Use ProximityPrompt for things the walks up to. Use ContextActionService for things triggered by a key binding. Use ClickDetector only for legacy compatibility.
Add a ProximityPrompt to a part called 'Door'. Set ActionText to 'Open', ObjectText to 'Door', and print the player's name when triggered.
local door = workspace.Door\n-- create and configure the ProximityPrompt, then connect TriggeredEnabled, don't reparent it.Next: — assigning to .