# ProximityPrompt

ProximityPrompt : `Instance`

## Overview

ProximityPrompt is a class that displays interactive actions and input prompts on the screen when a player approaches an 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.

## Properties

### HoldDuration

`number`

The duration in seconds that the button must be held to activate the prompt. Setting this to 0 activates the prompt immediately upon pressing.

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.HoldDuration = 1.5
```

### MaxActivationDistance

`number`

The maximum distance at which a player's character can activate the prompt.

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.MaxActivationDistance = 5
```

### ObjectText

`string`

The object name text displayed in the prompt UI.

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.ObjectText = "Treasure chest"
```

### ActionText

`string`

The action instruction text displayed in the prompt UI.

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.ActionText = "Open"
```

### KeyboardKeyCode

`Enum.KeyCode`

Specifies the keyboard key used to activate the prompt.

It is not displayed on mobile environments, so it is recommended to use it only for testing convenience in the Studio play test environment.

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.KeyboardKeyCode = Enum.KeyCode.E
```

### Exclusivity

`Enum.ProximityPromptExclusivity`

Specifies how many prompts can be shown simultaneously when multiple prompts share the same button.

* `OnePerButton`: Only one prompt is shown per key.
* `OneGlobally`: Only one prompt is shown globally.
* `AlwaysShow`: Always shown regardless of other prompts.

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.Exclusivity = Enum.ProximityPromptExclusivity.OnePerButton
```

### ClickablePrompt

`boolean`

Specifies whether the prompt can be activated by a mouse click.

It does not function in mobile environments, so it is recommended to use it only for testing convenience in the Studio play test environment.

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.ClickablePrompt = true
```

### Enabled

`boolean`

Specifies whether the prompt is enabled. Setting this to false hides the prompt.

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.Enabled = false
```

### UIOffset

`Vector2`

Specifies the screen offset (in pixels) of the prompt UI.

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.UIOffset = Vector2.new(0, 50)
```

### RequiresLineOfSight

`boolean`

Specifies whether a clear line of sight to the object is required to activate the prompt.&#x20;

When true, prompts on objects blocked by obstacles will not be activated.

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.RequiresLineOfSight = true
```

## Methods

### InputHoldBegin

Called when a hold input begins.

#### Parameters

#### Return

| `void` |   |
| ------ | - |

#### Code Samples

```lua
local prompt = workspace.InteractPart.ProximityPrompt
prompt:InputHoldBegin()
```

### InputHoldEnd

Called when a hold input ends.

#### Parameters

#### Return

| `void` |   |
| ------ | - |

#### Code Samples

```lua
local prompt = workspace.InteractPart.ProximityPrompt
prompt:InputHoldEnd()
```

## Events

### Triggered

This event fires when a player successfully activates the prompt.

Use this event to handle the logic that should run when the prompt is actually executed.

#### Parameters

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.Triggered:Connect(function()
    print("Prompt triggered!")
end)
```

### TriggerEnded

This event fires when an in-progress prompt trigger completes or is cancelled.

#### Parameters

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.TriggerEnded:Connect(function()
    print("Trigger ended.")
end)
```

### PromptButtonHoldBegan

This event fires when a player begins holding the prompt button.

#### Parameters

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.PromptButtonHoldBegan:Connect(function()
    print("Hold began.")
end)
```

### PromptButtonHoldEnded

This event fires when a player releases the prompt button.

#### Parameters

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.PromptButtonHoldEnded:Connect(function()
    print("Hold ended.")
end)
```

### PromptShown

This event fires when the prompt UI becomes visible on screen.

This event only functions in the client environment.

#### Parameters

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.PromptShown:Connect(function()
    print("Prompt is now visible.")
end)
```

### PromptHidden

This event fires when the prompt UI is hidden from the screen.

This event only functions in the client environment.

#### Parameters

#### Code Samples

```lua
local Workspace = game:GetService("Workspace")
local Prompt = Workspace.Part.ProximityPrompt

Prompt.PromptHidden:Connect(function()
    print("Prompt is now hidden.")
end)
```

## See also

{% content-ref url="../../../manual/studio-manual/object/proximityprompt" %}
[proximityprompt](https://docs.overdare.com/manual/studio-manual/object/proximityprompt)
{% endcontent-ref %}
