Volt

compareinstances

Compares if two references point to the same instance.

Syntax

compareinstances(a: Instance, b: Instance) -> boolean

Parameters

ParameterTypeDescription
aInstanceFirst instance reference
bInstanceSecond instance reference

Returns

TypeDescription
booleantrue if both point to the same instance

Description

compareinstances checks if two instance references point to the same underlying Roblox instance, even if they were created with cloneref.

Example

local part = workspace.Part
local clone = cloneref(part)
local other = workspace.OtherPart

-- Normal comparison fails for cloneref
print(part == clone) -- false

-- compareinstances works correctly
print(compareinstances(part, clone)) -- true
print(compareinstances(part, other)) -- false

Use Case

local function findInTable(tbl, target)
    for _, item in ipairs(tbl) do
        if typeof(item) == "Instance" and compareinstances(item, target) then
            return true
        end
    end
    return false
end
  • cloneref - Clone an instance reference

On this page