Open Asterune
Reacting to players

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.

InteractionAPIExecution side
Click a partClickDetectorServer event
Activate a nearby promptProximityPromptServer event
Keyboard, pointer, touch, or gamepadInputServiceClient
Sit on a partSeatObserve 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.

Luau
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.

Luau
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.

Luau
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.