articles/Creating GUI Buttons|Creating GUI Buttons article, you learned how to create on-screen buttons for menus, interface actions, and more. Interactivity can also be handled through prompts that appear when players approach in-game objects like doors, switches, or even non-player characters.
The remainder of this course uses the Dungeon Delve project as a showcase. To follow along, open it in Studio before proceeding.
Creating a Prompt
On-screen prompts are generated by a
ProximityPrompt object parented to an
- Select the PrisonDoor model in the 3D view or from the Explorer (Workspace → PromptObjects → PrisonDoor).
- Expand its tree and select the Door object.
- Placing a prompt on an
Attachmentgives you more control on where the point of interaction occurs, versus placing it directly on the part/model. Insert a new Attachment and rename it to PromptAttachment.
- Locate the new attachment’s Position property and set it to -2.25, -0.5, -0.5. This will move it in front of the door’s key hole.
- Hover over PromptAttachment and insert a new ProximityPrompt object.
Prompts consist of three primary elements, each of which can be controlled by the following properties:
- ObjectText — An optional name for the object being interacted with.
- ActionText — An optional action name shown to the player.
- KeyboardKeyCode — The keyboard key which will trigger the prompt.
- GamepadKeyCode — The gamepad button which will trigger the prompt.
- In the Properties window, locate the ObjectText property and type in Door.
- For the ActionText property, type in Pick Lock.
Prompts appear when the player’s character moves within the defined MaxActivationDistance range of the prompt object’s parent.
The default value works well in most cases, but you can push player interaction closer to the lock by changing MaxActivationDistance to 4.
The HoldDuration property value determines how quickly the prompt’s action is triggered, in seconds. Since this door must be picked to unlock it, change the HoldDuration property to 4.
Responding to Player Input
The best way to detect prompt events is through
ProximityPromptService — this lets you detect events centrally without attaching a script to each prompt object. A basic framework is as follows:
||Fires when a player interacts with a prompt (after the duration for a prompt with non-zero
||Fires when a player begins interacting with a prompt of non-zero
||Fires when a player stops interacting with a prompt of non-zero
In the Dungeon Delve project, these events are managed by the PromptEvents script within ServerScriptService.
Inside the script, the events above simply call functions within the ObjectActions
ModuleScript, also located in ServerScriptService.
As you can see, proximity prompts are a convenient and customizable solution for in-game object interaction. Check out the
ProximityPromptService reference pages for even more ways to control prompt behavior, and explore other interactive objects in Dungeon Delve for creative inspiration!