replica:ListenToWrite(action_name: string, listener: (...any) -> ()): () -> ()

Server Only

Fires locally on the server whenever the named Action executes (via Actions.Foo(...) or Write(...)), receiving the same arguments. Useful for side effects like triggering a save after a specific Action, without coupling that logic into the Action itself.

Parameters

action_name*
string
Name of the Action to observe.
listener*
(...any) -> ()
Called with the same arguments passed to the Action.

Returns

() -> ()Disconnect function.
replica:ListenToWrite("BuyItem", function(item_id, price)
    DataStoreService:SaveAsync(player, replica.Data)
end)