observable T
A ValueBase whose identifier reads and writes .Value. Assigning fires Changed.
Syntax
Section titled “Syntax”observable T name = value;name.OnChange(fn);name = next;Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
T | type | int → IntValue, float/double → NumberValue, string → StringValue, bool → BoolValue, else ObjectValue. |
Return value
Section titled “Return value”The ValueBase instance.
Luau emit
Section titled “Luau emit”Instance.new("...Value"); name.Value = …
Description
Section titled “Description”Reading name in an expression uses .Value. Writing name = x writes .Value and fires Changed.
.OnChange(fn) is Changed:Connect(fn).
Example
Section titled “Example”observable int coins = 100;coins.OnChange(func (int newValue) { post("now " .: newValue);});coins = 50;post(coins);Emits:
local coins: IntValue = Instance.new("IntValue")coins.Value = 100coins.Changed:Connect(function(newValue: number) print("now " .. newValue)end)coins.Value = 50print(coins.Value)