Observable and signals
Two ways to broadcast change: observable (a ValueBase) and signal (a typed BindableEvent).
observable — fire by assigning
Section titled “observable — fire by assigning”observable int coins = 100;
coins.OnChange(func (int newValue) { post("Coins changed to: " .: newValue);});
coins = 50; // writes .Value and fires Changedpost(coins); // reads .ValueT | Instance |
|---|---|
int | IntValue |
float double | NumberValue |
string | StringValue |
bool | BoolValue |
| anything else | ObjectValue |
signal — fire with .Fire
Section titled “signal — fire with .Fire”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();| API | Role |
|---|---|
.Fire(...) | send |
~>Connect | listen until disconnected |
~>Once | listen once |
.Wait() | yield until next fire |
Property change “shots”
Section titled “Property change “shots””humanoid.GetPropertyChangedSignal("Health")~>Connect(func () { post(humanoid.Health);});API pages: Signals, Observables.
Next: Guard and match.