PcoWSkbVqDnWTu_dm2ix

Implementing Proximity Prompts

Implementing Proximity Prompts

10 min

In addition to articles/Creating GUI Buttons|GUI buttons, game interactivity can be handled through proximity prompts that appear when players approach in-game objects like doors, switches, or even non-player characters.

Using this feature you can:

  • Indicate what objects can be interacted with in the world.
  • Display what action can be taken on the object and trigger the action through user input.
  • Display the correct input for all input types (keyboard/gamepad/touchscreen).
  • Let players trigger the action immediately or “hold” to trigger the action after a time.

Creating a Prompt Object

To begin, create a ProximityPrompt object as a child of a BasePart, Model, or Attachment.

Appearance

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 — On PC, the key which will trigger the prompt.
  • GamepadKeyCode — On console, the gamepad button which will trigger the prompt.

Visibility

Prompts appear when the player’s character moves within the defined MaxActivationDistance range around the ProximityPrompt object.

MaxActivationDistance

Visibility can also be controlled by the RequiresLineOfSight property. This is true by default, meaning the prompt will only be shown if there’s a clear path from the camera to the prompt object.

RequiresLineOfSight

Interactivity

The HoldDuration property value determines whether the prompt’s action is triggered immediately (value of 0) or after a duration (number of seconds).

HoldDuration

Interactivity can also be modified by the ClickablePrompt property. If true, players can interact by clicking/tapping the on-screen prompt or by pressing the specified key/button. If false, players can only interact via the key/button, except on phones and tablets where tapping is always supported.

Exclusivity

The Exclusivity property determines how and when a prompt appears, based on the camera’s view direction and the character’s distance from the prompt.

OnePerButton means that one prompt will be shown per input keycode. If multiple in-range prompts use different keycodes, all will appear. If multiple in-range prompts use the same keycode, only one will appear at any given time, depending on the camera's view direction.

OnePerButton — Door prompt using E and lantern prompt using T.

If multiple prompts are set to OneGlobally exclusivity, only one will appear at any given time, regardless of how close they are to each other. The camera's view direction will determine which prompt appears. This setup is useful for minimizing prompt distraction for several nearby prompt objects.

OneGlobally — Only one prompt within range can appear, regardless of the key code

Exclusivity of AlwaysShow means that the prompt will always show when in range, assuming no other factors prevent it from appearing. Be cautious when using this setup, as all visible prompts using the same keycode will be triggered by that key or gamepad button.

AlwaysShow — All prompts within range appear, even if using the same key code

Responding to Player Input

Prompt events can be detected either on the ProximityPrompt object itself or globally through ProximityPromptService.

Event Description
ProximityPromptService/PromptTriggered|PromptTriggered Fires when a player interacts with a prompt (after the duration for a prompt with non-zero ProximityPrompt/HoldDuration|HoldDuration).
ProximityPromptService/PromptTriggerEnded|PromptTriggerEnded Triggers when the player stops interacting with a prompt.
ProximityPromptService/PromptButtonHoldBegan|PromptButtonHoldBegan Fires when a player begins interacting with a prompt of non-zero ProximityPrompt/HoldDuration|HoldDuration.
ProximityPromptService/PromptButtonHoldEnded|PromptButtonHoldEnded Fires when a player stops interacting with a prompt of non-zero ProximityPrompt/HoldDuration|HoldDuration
ProximityPromptService/PromptShown|PromptShown Triggers in LocalScript|LocalScripts when a prompt is shown.
ProximityPromptService/PromptHidden|PromptHidden Triggers in LocalScript|LocalScripts when a prompt is hidden.

A basic framework using ProximityPromptService is as follows. Fully working prompt examples are also located in the Dungeon Delve sample place.

Dungeon Delve

Interact with various proximity prompts in a mini-dungeon.
Play
Tags:
  • proximity prompt
  • prompt
  • interaction