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

-- These are the constraints for a 32-bit signed integer
local INT_MAX = 2 ^ 31 - 1
local INT_MIN = -(2 ^ 31)
local vInteger = Instance.new("IntValue")
vInteger.Changed:Connect(print)
-- Some small values
vInteger.Value = 5
vInteger.Value = 0
vInteger.Value = -0 -- No change - same as 0
-- Min value
vInteger.Value = INT_MIN
-- Max value
vInteger.Value = INT_MAX
-- Max value plus one; this causes integer overflow!
-- The IntValue changes to INT_MIN!
vInteger.Value = INT_MAX + 1

Summary

Properties

Events

Properties

Value

read parallel

Used to hold an integer.

Methods

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

local value = Instance.new("IntValue")
value.Parent = workspace
local function onValueChanged(newValue)
print(newValue)
end
value.Changed:Connect(onValueChanged)
value.Value = 20