PcoWSkbVqDnWTu_dm2ix
Collapse Sidebar

ProximityPrompt

Show deprecated

ProximityPrompt

Show deprecated

The ProximityPrompt is an object that allows developers to prompt users to interact with an object in the 3D world, such as opening a door or picking up an item.

ProximityPrompts work when parented to a Part, Model, or Attachment in the workspace.
In order to detect when the user interacts with the object, listen for the Triggered event on the ProximityPrompt in either a Script or LocalScript, as in this simple example:

workspace.Part.ProximityPrompt.Triggered:Connect(function(player)
    print("The user interacted with me!")
end)

When a user is near, a UI will appear to prompt them for input. This works for all input types - keyboard, gamepad, and touchscreen.

The provided UI can be swapped out for your own custom UI. See ProximityPrompt/Style for details.

Prompt 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 — The keyboard key which will trigger the prompt.
  • GamepadKeyCode — The gamepad button which will trigger the prompt.

See also

For more information regarding ProximityPrompts, take a look at the Proximity Prompts.

Properties

string

ActionText

The action text shown to the user

bool

AutoLocalize

Whether the prompt’s ProximityPrompt/ActionText and ProximityPrompt/ObjectText will be localized according to the ProximityPrompt/RootLocalizationTable

bool

ClickablePrompt

Whether the prompt can be activated by clicking/tapping on the prompt UI

bool

Enabled

Whether this prompt should be shown

ProximityPromptExclusivity

Exclusivity

Used to customize which prompts can be shown at the same time

KeyCode

GamepadKeyCode

The gamepad button the player should press to trigger the prompt

float

HoldDuration

The duration, in seconds, that the player must hold the button/key down to trigger the prompt

KeyCode

KeyboardKeyCode

The key the player should press to trigger the prompt

float

MaxActivationDistance

The maximum distance a Player’s Player/Character|character can be from the ProximityPrompt for the prompt to appear

string

ObjectText

An optional property that determines the object name text shown to the user

bool

RequiresLineOfSight

Whether the prompt is hidden if the path between the player’s Camera and object parented to the ProximityPrompt is obstructed

LocalizationTable

RootLocalizationTable

A reference to a LocalizationTable to be used to apply automated localization to this ProximityPrompt’s ProximityPrompt/ActionText and ProximityPrompt/ObjectText

ProximityPromptStyle

Style

The style of the prompt’s UI

Vector2

UIOffset

The pixel offset applied to the prompt’s UI

Inherited from Instance: Show Hide

bool

Archivable

Determines if an Instance can be cloned using /Instance/Clone or saved to file.

string

ClassName

[ReadOnly] [NotReplicated]

A read-only string representing the class this Instance belongs to

int

DataCost

[Hidden] [ReadOnly] [NotReplicated] [Deprecated]

The cost of saving the instance using data persistence.

string

Name

A non-unique identifier of the Instance

Instance

Parent

[NotReplicated]

Determines the hierarchical parent of the Instance

bool

RobloxLocked

[Hidden]

A deprecated property that used to protect CoreGui objects

bool

archivable

[Hidden] [NotReplicated] [Deprecated]
string

className

[ReadOnly] [NotReplicated] [Deprecated]

Functions

void

InputHoldBegin ( )

Fires a signal indicating that the user began pressing the prompt GUI button

void

InputHoldEnd ( )

Fires a signal indicating that the user ended pressing the prompt GUI button

Inherited from Instance: Show Hide

void

ClearAllChildren ( )

This function destroys all of an Instance’s children.

Instance

Clone ( )

Create a copy of an object and all its descendants, ignoring objects that are not Instance/Archivable|Archivable

void

Destroy ( )

Sets the Instance/Parent property to nil, locks the Instance/Parent property, disconnects all connections and calls Destroy on all children.

Instance

FindFirstAncestor ( string name )

Returns the first ancestor of the Instance whose Instance/Name is equal to the given name.

Instance

FindFirstAncestorOfClass ( string className )

Returns the first ancestor of the Instance whose Instance/ClassName is equal to the given className.

Instance

FindFirstAncestorWhichIsA ( string className )

Returns the first ancestor of the Instance for whom Instance/IsA returns true for the given className.

Instance

FindFirstChild ( string name , bool recursive )

Returns the first child of the Instance found with the given name.

Instance

FindFirstChildOfClass ( string className )

Returns the first child of the Instance whose Instance/ClassName|ClassName is equal to the given className.

Instance

FindFirstChildWhichIsA ( string className , bool recursive )

Returns the first child of the Instance for whom Instance/IsA returns true for the given className.

Instance

GetActor ( )

Variant

GetAttribute ( string attribute )

Returns the attribute which has been assigned to the given name

RBXScriptSignal

GetAttributeChangedSignal ( string attribute )

Returns an event that fires when the given attribute changes

Dictionary

GetAttributes ( )

Returns a dictionary of string → variant pairs for each of the Instance|Instance’s attributes

Objects

GetChildren ( )

Returns an array containing all of the Instance’s children.

string

GetDebugId ( int scopeLength )

[NotBrowsable]

Returns a coded string of the Instances DebugId used internally by Roblox.

Array

GetDescendants ( )

[CustomLuaState]

Returns an array containing all of the descendants of the instance

string

GetFullName ( )

Returns a string describing the Instance’s ancestry.

RBXScriptSignal

GetPropertyChangedSignal ( string property )

Get an event that fires when a given property of an object changes.

bool

IsA ( string className )

[CustomLuaState]

Returns true if an Instance’s class matches or inherits from a given class

bool

IsAncestorOf ( Instance descendant )

Returns true if an Instance is an ancestor of the given descendant.

bool

IsDescendantOf ( Instance ancestor )

Returns true if an Instance is a descendant of the given ancestor.

void

Remove ( )

[Deprecated]

Sets the object’s Parent to nil, and does the same for all its descendants.

void

SetAttribute ( string attribute , Variant value )

Sets the attribute with the given name to the given value

Instance

WaitForChild ( string childName , double timeOut )

[CustomLuaState] [CanYield]

Returns the child of the Instance with the given name. If the child does not exist, it will yield the current thread until it does.

Objects

children ( )

[Deprecated]

Returns an array of the object’s children.

Instance

clone ( )

[Deprecated]
void

destroy ( )

[Deprecated]
Instance

findFirstChild ( string name , bool recursive )

[Deprecated]
Objects

getChildren ( )

[Deprecated]
bool

isA ( string className )

[Deprecated] [CustomLuaState]
bool

isDescendantOf ( Instance ancestor )

[Deprecated]
void

remove ( )

[Deprecated]

Events

RBXScriptSignal

PromptButtonHoldBegan ( Instance playerWhoTriggered )

Triggered when a player begins holding down the ProximityPrompt/KeyboardKeyCode|key/button connected to a prompt with a non-zero ProximityPrompt/HoldDuration

RBXScriptSignal

PromptButtonHoldEnded ( Instance playerWhoTriggered )

Triggers when the player ends holding down the button on a prompt with a non-zero ProximityPrompt/HoldDuration

RBXScriptSignal

PromptHidden ( )

Triggers when the prompt becomes hidden

RBXScriptSignal

PromptShown ( ProximityPromptInputType inputType )

Triggers when the ProximityPrompt|prompt becomes visible

RBXScriptSignal

TriggerEnded ( Instance playerWhoTriggered )

Triggers when ProximityPrompt/KeyboardKeyCode|key/button is released, for longer events where the user is required to hold down the button

RBXScriptSignal

Triggered ( Instance playerWhoTriggered )

Triggered when the prompt ProximityPrompt/KeyboardKeyCode|key/button is pressed, or after a specified amount of time holding the button, if ProximityPrompt/HoldDuration is used

Inherited from Instance: Show Hide

RBXScriptSignal

AncestryChanged ( Instance child , Instance parent )

Fires when the Instance/Parent property of the object or one of its ancestors is changed.

RBXScriptSignal

AttributeChanged ( string attribute )

Fires whenever an attribute is changed on the Instance

RBXScriptSignal

Changed ( string property )

Fired immediately after a property of an object changes.

RBXScriptSignal

ChildAdded ( Instance child )

Fires when an object is parented to this Instance.

RBXScriptSignal

ChildRemoved ( Instance child )

Fires when a child is removed from this Instance.

RBXScriptSignal

DescendantAdded ( Instance descendant )

Fires when a descendant is added to the Instance

RBXScriptSignal

DescendantRemoving ( Instance descendant )

Fires immediately before a descendant of the Instance is removed.

RBXScriptSignal

childAdded ( Instance child )

[Deprecated]

Code Samples


Using a Proximity Prompt with a Seat

In the example below, a user must interact with a chair to sit in it. Paste this into a Script that is a child of a ProximityPrompt, which is itself a sibling of a Seat object named Seat.

local proximityPrompt = script.Parent
local seat = proximityPrompt.Parent.Seat

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
    if seat.Occupant then
        proximityPrompt.Enabled = false
    else
        proximityPrompt.Enabled = true
    end
end)

proximityPrompt.Triggered:Connect(function(player)
    seat:Sit(player.Character.Humanoid)
end)