NumberValue

Show Deprecated

A NumberValue is an object whose purpose is to store a single Lua number, defined to be double-precision floating point number, or more commonly known as a double. This stores a number in 64 bits (8 bytes) using the IEEE 754 representation (1 sign bit, 11 exponent bits and 52 fractional bits). The maximum numerical value that may be stored is 2^53, or 9,007,199,254,740,992, and the minimum is -9,007,199,254,740,992. It stores up to 15 digits of precision.

Like all "-Value" objects, this single value is stored in the Value property. The Changed event for this (and other objects like it) will fire with the new value being stored in the object, instead of a string representing the property being changed.

Code Samples

Changed Event

1-- Demonstrate the Changed event by creating a Part
2local part = Instance.new("Part")
3part.Changed:Connect(print)
4-- This fires Changed with "Transparency"
5part.Transparency = 0.5
6-- Similarly, this fires Changed with "Number"
7part.Name = "SomePart"
8-- Since changing BrickColor will also change other
9-- properties at the same time, this line fires Changed
10-- with "BrickColor", "Color3" and "Color3uint16".
11part.BrickColor = BrickColor.Red()
12
13-- A NumberValue holds a double-precision floating-point number
14local vNumber = Instance.new("NumberValue")
15vNumber.Changed:Connect(print)
16-- This fires Changed with 123.456 (not "Value")
17vNumber.Value = 123.456
18-- This does not fire Changed
19vNumber.Name = "SomeNumber"
20
21-- A StringValue stores one string
22local vString = Instance.new("StringValue")
23vString.Changed:Connect(print)
24-- This fires Changed with "Hello" (not "Value")
25vString.Value = "Hello"

Summary

Properties

Used to hold a double value.

Events


Fired whenever the NumberValue.Value is changed.

Methods

Properties

Value

Used to hold a double value.

Events

Changed

This event fires whenever the NumberValue.Value property is changed.

This event, like other changed events, can be used to track when an NumberValue changes and to track the different values that it may change to.

For instance, this even may be useful in games that rely on NumberValues to track game states and values, such as item IDs.

Equivalent changed events exist for similar objects, such as ObjectValue and StringValue, depending on what object type best suits the need.

Parameters

value: number

The value after the change.


Code Samples

NumberValue Changed

1local function printValue(value)
2 print(value)
3end
4
5workspace.NumberValue.Changed:Connect(printValue)
6
7workspace.NumberValue.Value = 20

Methods