cloneref

Creates a new reference to an instance that compares as different.

Syntax

cloneref(instance: Instance) -> Instance

Aliases

  • clonereference

Parameters

ParameterTypeDescription
instanceInstanceThe instance to clone a reference to

Returns

TypeDescription
InstanceA new reference to the same instance

Description

cloneref creates a new reference to an instance. The cloned reference points to the same underlying object, but the two references are not equal when compared with ==.

Example

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

-- Both reference the same instance
print(folder.Name) -- "Original"
print(clone.Name)  -- "Original"

-- But they compare as different
print(folder == clone) -- false

-- Changes through one affect the other
clone.Name = "Renamed"
print(folder.Name) -- "Renamed"

Verification

-- Verify they're the same underlying instance
print(compareinstances(folder, clone)) -- true