What is a ProximityPrompt?
ProximityPrompt is a method to prompt users and allow them to interact with an object in the 3D world, such as opening a door or picking up an item. This is a system that developers have been writing on their own, but we wanted to make it easy for devs, and also have a universal system across roblox, so players easily understand how to interact with objects.
Using this new feature you can:
- Indicate what objects can be interacted with in the world
- Display what action(s) can be taken on the object
- Trigger that action(s) through user input
- Display the correct input for all input types (keyboard/gamepad/touchscreen)
- Use a tap to instantly trigger the action, or a hold to trigger the action over a period of time
- Use the default UI provided or add your own custom UI
How do I use it?
Create an object of type ProximityPrompt in the workspace as a child of a part, model, or attachment. Modify any properties as desired, such as ActionText and KeyboardKeyCode to adjust how the prompt looks or which button the user must press to interact with it.
In order to detect when the user interacts with the object, listen for the Triggered event on the ProximityPrompt in either a Script or LocalScript, as in this simple example:
workspace.Part.ProximityPrompt.Triggered:Connect(function(player) print("The user interacted with me!") end)
Launch the game in Studio, and walk over to where the prompt was placed in the world. You will be able to see the UI, and you should be able to interact with it by pressing the E key by default (or whatever you changed KeyboardKeyCode to).
Tap button to interact - pick up an object, open a door, flip a switch, talk to NPC.
Hold button to trigger immediate action - require player to hold button for X seconds before picking a lock or opening a chest, which leaves the player exposed. HoldDuration is a useful property that, if non-zero, will require the player to hold the button down for a duration before the action is triggered. A progress bar animation indicates how long the button needs to be held.
Hold button for continuous action - player holds button to heal a teammate or water a plant over time. The action continues while the button is held and stops when the button is let go. “Hold” events are supported. Use the TriggerEnded event along with Triggered for this scenario. (Triggered and TriggerEnded events always come in pairs.)
A tutorial on how to use the feature can be found here:
Complete documentation is available here, including the list of properties you can change, and a method to fully customize your prompts.