# ProximityPrompt

## Overview

ProximityPrompt is a feature that displays available interactions and input prompts when a player approaches an object. Players can press the displayed input key to interact with the object.

This feature is used as a UI element that intuitively informs players which objects can be interacted with. It can be applied to various objects such as chests, doors, resources, NPCs, and devices, and is widely used in exploration, RPG, and survival genre games.

ProximityPrompt supports two types of interaction methods: Press input and Hold input.

## How to Use

ProximityPrompt can be used by placing it under BasePart, Attachment, or Model.

When a player character enters the activation distance (MaxActivationDistance) of the object where the prompt is configured, a UI that guides input is automatically displayed.

<figure><img src="https://2064130887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FhrvYlLq1mQAq0V0vwPsb%2Fuploads%2FB3If0xIF9kG72hpf6JhE%2Fimage.png?alt=media&#x26;token=f70988c7-0e09-4bc0-8b76-c42de80619a9" alt=""><figcaption></figcaption></figure>

Players can interact with the object by pressing the displayed input key. The input method automatically changes depending on the platform.

* PC : Keyboard input
* Mobile : Touch input

### Property Summary

<table><thead><tr><th width="247">Property</th><th>Description</th></tr></thead><tbody><tr><td>Hold Duration</td><td>Sets the time (in seconds) the button must be held down. If HoldDuration is greater than 0, the button must be held for a certain amount of time for the interaction to be executed.</td></tr><tr><td>Max Activation Distance</td><td>The maximum distance at which the prompt is displayed.</td></tr><tr><td>Object Text</td><td>The text that displays the name of the object being interacted with.</td></tr><tr><td>Action Text</td><td>The interaction text shown to the player. (e.g., Open, Talk, Mine)</td></tr><tr><td>Keyboard Key Code</td><td>Specifies the keyboard input key used for interaction in a PC environment.</td></tr><tr><td>Exclusivity</td><td>Defines the display rule for prompts shown at the same time. Depending on the Exclusivity setting, multiple prompts may not be displayed simultaneously.</td></tr><tr><td>Clickable Prompt</td><td>Determines whether the prompt UI can be clicked to interact in a PC environment.</td></tr><tr><td>Enabled</td><td>Determines whether the prompt is displayed.</td></tr><tr><td>UIOffset</td><td>Sets the screen position offset of the prompt UI.</td></tr><tr><td>Requires Line Of Sight</td><td>Determines whether the prompt should be hidden if the object is obstructed from the camera's view.</td></tr></tbody></table>

### Script Feature

Using scripts, you can execute specific actions when the prompt is triggered.

```lua
local Prompt = script.Parent

local function OnTriggered(player)
    print(player.Name .. " Triggered")
end
Prompt.Triggered:Connect(OnTriggered)

local function OnTriggerEnded(player)
    print(player.Name .. " TriggerEnded")
end
Prompt.TriggerEnded:Connect(OnTriggerEnded)
```

Learn More

{% content-ref url="../../../development/api-reference/classes/proximityprompt" %}
[proximityprompt](https://docs.overdare.com/development/api-reference/classes/proximityprompt)
{% endcontent-ref %}

{% content-ref url="../../../development/api-reference/classes/proximityprompservice" %}
[proximityprompservice](https://docs.overdare.com/development/api-reference/classes/proximityprompservice)
{% endcontent-ref %}

## Notes

* ProximityPrompt functions properly only when placed under BasePart, Attachment, or Model.
* Whether the prompt is displayed is calculated based on the distance between the player and the center point of the object.
* When Device Emulator is enabled in Studio, or when the experience is running on a mobile device, the KeyboardKeyCode and ClickablePrompt settings do not affect the behavior. In mobile environments, prompts are displayed and interacted with using touch input.

## Usage Examples

* When a player approaches a treasure chest placed in the world, an Open prompt appears. The player can press the input key to open the chest and obtain items or rewards.
* When a player approaches an ore object, a Mine prompt appears, allowing the player to mine the resource and obtain materials.
* When a player approaches an NPC, a Talk prompt appears, allowing the player to start a conversation or interact with quests and shops.
* When a player approaches a door or device, an Open or Activate prompt appears, allowing the player to open the door or operate the device.
