# 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

### 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"
```

### AutoLocalize

`boolean`

Determines whether automatic localization (Auto Translation) is applied to this ProximityPrompt's ActionText and ObjectText. If AutoLocalize is true, the text is also included in Automatic Text Collection (ATC).

The default value is true. If set to false, the prompt text is not translated.

#### Code Samples

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

Prompt.AutoLocalize = false
```

### 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
```

### 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
```

### 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
```

### 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
```

### 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"
```

### RequiresLineOfSight

`boolean`

Specifies whether a clear line of sight to the object is required to activate the prompt.

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
```

### 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)
```

## 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

### 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)
```

### 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)
```

### 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)
```

### 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)
```

## See also

{% content-ref url="/pages/pJZBTtT2zwhjOt2pGLTm" %}
[ProximityPrompt](/manual/studio-manual/object/proximityprompt.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.overdare.com/development/api-reference/classes/proximityprompt.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
