Skip to content

Observable and signals

Two ways to broadcast change: observable (a ValueBase) and signal (a typed BindableEvent).

observable int coins = 100;
coins.OnChange(func (int newValue) {
post("Coins changed to: " .: newValue);
});
coins = 50; // writes .Value and fires Changed
post(coins); // reads .Value
TInstance
intIntValue
float doubleNumberValue
stringStringValue
boolBoolValue
anything elseObjectValue
signal<Player, int> OnCoinsUpdated;
OnCoinsUpdated~>Connect(func (Player player, int amount) {
post(player.Name .: ": " .: amount);
});
OnCoinsUpdated~>Once(func (Player player, int amount) {
post("first pay");
});
OnCoinsUpdated.Fire(player, 500);
OnCoinsUpdated.Wait();
APIRole
.Fire(...)send
~>Connectlisten until disconnected
~>Oncelisten once
.Wait()yield until next fire
humanoid.GetPropertyChangedSignal("Health")~>Connect(func () {
post(humanoid.Health);
});

API pages: Signals, Observables.

Next: Guard and match.