compareinstances
Compares if two references point to the same instance.
Syntax
compareinstances(a: Instance, b: Instance) -> booleanParameters
| Parameter | Type | Description |
|---|---|---|
a | Instance | First instance reference |
b | Instance | Second instance reference |
Returns
| Type | Description |
|---|---|
boolean | true 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)) -- falseUse 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
endRelated Functions
cloneref- Clone an instance reference