Replicated input actions¶
Set InputAction.Replicated = true on a server-spawned action to stream each
player's button edges and axis values from the client to the server inside
the player's input ticks. A player can send up to 32 replicated actions and 8
analog axis values ("Axis1" uses 1, "Axis2" uses 2) across enabled
contexts, filled highest Priority first.
Server scripts read per-player state with IsDown(player),
WasPressed(player), WasReleased(player), GetAxis(player), and
GetVector(player), or subscribe to Component.InputAction.Pressed and
Component.InputAction.Released which pass the acting player. Clients can
rebind or toggle replicated actions locally with Override on
InputBinding or InputContext.Enabled, and the server receives the
resulting action state.
-- Server script: dash when a player presses Q or ButtonB.
local combat = World.Spawn({ InputContext = { Priority = 1000 } })
local dash = World.Spawn({
InputAction = { Kind = "Button", Replicated = true },
InputBinding = { Inputs = { "Q", "ButtonB" } },
})
dash.Parent = combat
dash:On(Component.InputAction.Pressed, function(player: Entity)
print(player.Name .. " dashed")
end)
function Update(dt: number)
local action = dash.InputAction
if not action then
return
end
for _, player in Players.All() do
if action:IsDown(player) then
print(player.Name .. " holding dash")
end
end
end
Predicted ActionBits¶
For client-predicted character movement such as a dash or wall jump that runs
on the same physics tick on both the owning client and the server, use
CharacterMoveIntent.ActionBits (sixteen bits, 0 to 65535) with
CharacterAbilities. The owning
client writes ActionBits in Update, and the server reads the same bits in
that physics tick.