IntValue

Show Deprecated

An IntValue is an object that stores a single signed 64-bit integer. Integers do not include decimal points. The highest value that can be stored is 2^63-1, or around 9.2 quintillion. Attempting to store numbers larger than this may cause integer overflow. The lowest value that can be stored is -2^63, or about negative 9.2 quintillion. For values outside of this range, use a NumberValue instead. Like all "-Value" objects, this single value is stored in the Value property. The IntValue.Changed event for this (and other objects like it) will run with the new value being stored in the object, instead of a string representing the property being changed.

Code Samples

IntValue Limits and Integer Overflow

1-- These are the constraints for a 32-bit signed integer
2local INT_MAX = 2 ^ 31 - 1
3local INT_MIN = -(2 ^ 31)
4
5local vInteger = Instance.new("IntValue")
6vInteger.Changed:Connect(print)
7-- Some small values
8vInteger.Value = 5
9vInteger.Value = 0
10vInteger.Value = -0 -- No change - same as 0
11-- Min value
12vInteger.Value = INT_MIN
13-- Max value
14vInteger.Value = INT_MAX
15-- Max value plus one; this causes integer overflow!
16-- The IntValue changes to INT_MIN!
17vInteger.Value = INT_MAX + 1

Summary

Properties

Used to hold an integer.

Events


Fired whenever the IntValue.Value of the IntValue is changed.

Methods

Properties

Value

Used to hold an integer.

Events

Changed

The Changed event fires whenever the IntValue.Value of the IntValue is changed. It will run with the new value being stored in the argument object, instead of a string representing the property being changed.

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

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

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

Parameters

value: number

The new value after the change.


Code Samples

How to Use IntValue.Changed

1local value = Instance.new("IntValue")
2value.Parent = workspace
3
4local function onValueChanged(newValue)
5 print(newValue)
6end
7
8value.Changed:Connect(onValueChanged)
9
10value.Value = 20

Methods