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 references point to the same underlying instance, even if they were created with cloneref.

Example

local folder = Instance.new("Folder")
local clone = cloneref(folder)
local other = Instance.new("Folder")

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

-- compareinstances works correctly
print(compareinstances(folder, clone)) -- true
print(compareinstances(folder, 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