Reacting to players
Handle clicks, proximity interactions, client input, and seating.
Use an interaction instance for actions on a part and InputService for raw
client input.
| Interaction | API | Execution side |
|---|---|---|
| Click a part | ClickDetector | Server event |
| Activate a nearby prompt | ProximityPrompt | Server event |
| Keyboard, pointer, touch, or gamepad | InputService | Client |
| Sit on a part | Seat | Observe Occupant |
Click a part
Parent a ClickDetector to the target part. MouseClick passes the player.
MaxActivationDistance sets the maximum activation distance in studs.
This server example requires a part named Button.
local detector = Instance.new("ClickDetector")
detector.MaxActivationDistance = 24
detector.Parent = workspace:WaitForChild("Button")
detector.MouseClick:Connect(function(player)
print(player.Name)
end)MouseHoverEnter and MouseHoverLeave report pointer hover changes.
Configure a proximity prompt
Parent a ProximityPrompt to the target part. ObjectText labels the object;
ActionText labels the action. HoldDuration is measured in seconds. A value of
0 activates on a press.
Triggered fires after activation completes. Hold events report the start and
end of a hold. Enabled = false disables the prompt without destroying it.
Handle client input
Run input handlers in a LocalScript. Began, Changed, and Ended pass an
InputObject and a gameProcessed flag. Ignore processed input when a shortcut
must not run during text entry or another handled interaction.
local InputService = game:GetService("InputService")
InputService.Began:Connect(function(input, gameProcessed)
if gameProcessed then
return
end
if input.UserInputType == Enum.UserInputType.Keyboard
and input.KeyCode == Enum.KeyCode.E then
print("interact")
end
end)Check UserInputType before reading device-specific fields. IsDown and
GetPressed query held inputs. GetDevices reports available devices and
LastDevice identifies the most recently used device.
Bind an action
BindAction associates a named callback with input bindings. Its optional third
argument controls touch-button creation; key and button enums follow it.
local InputService = game:GetService("InputService")
InputService:BindAction("Sprint", function(actionName, state, input)
print(state)
end, false, Enum.KeyCode.LeftShift)Call UnbindAction("Sprint") when the action is no longer available.
Observe seating
Seat.Occupant is the seated Humanoid or nil. Observe Changed and filter
for "Occupant" to detect changes. Disabling a seat prevents new seating but does
not eject the current occupant.