Skip to content

observable T

Type

A ValueBase whose identifier reads and writes .Value. Assigning fires Changed.

observable T name = value;
name.OnChange(fn);
name = next;
NameTypeDescription
Ttypeint → IntValue, float/double → NumberValue, string → StringValue, bool → BoolValue, else ObjectValue.

The ValueBase instance.

Instance.new("...Value"); name.Value = …

Reading name in an expression uses .Value. Writing name = x writes .Value and fires Changed.

.OnChange(fn) is Changed:Connect(fn).

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 = 100
coins.Changed:Connect(function(newValue: number)
print("now " .. newValue)
end)
coins.Value = 50
print(coins.Value)

OnChange · int · new