Why use NumberValue?
NumberValue is convenient for a small piece of inspectable state shared among scripts. Its Changed signal lets another script respond to updates; for complex systems, a regular Lua table may be simpler.
Try it in Roblox Studio
Put this Script in ServerScriptService. Open Output and Explorer to inspect the ScoreValue object.
Syntax
value.Value = 10
value.Changed:Connect(function(newValue) ... end)Examples
NumberValue state
Increment a score-like number and observe its change.
local score = Instance.new("NumberValue")
score.Name = "ScoreValue"
score.Parent = workspace
score.Changed:Connect(function(newValue)
print("Score changed to", newValue)
end)
score.Value = 10- NumberValue stores a number in its Value property.
- The Changed connection runs when Value changes and receives the new value.
- The handler is connected before setting Value, so this example prints the update.
Best practices
- Use server-owned values for authoritative scores.
- Disconnect long-lived event handlers when their owning system is removed.
Runtime & versions
Luau host; Roblox engine examples require Roblox Studio. Feature availability depends on the language and runtime version used by your project; consult the official reference below.
Luau documentation