cloneref
Returns a second reference to an Instance that is a different Luau value.
Syntax
cloneref(object: Instance) -> Instance
Also available as
clonereferenceclone_ref
Parameters
| Parameter | Type | Description |
|---|---|---|
object | Instance | The Instance to reference. |
Returns
| Type | Description |
|---|---|
Instance | A new reference to the same Instance. |
Description
Normally the engine hands out one userdata per Instance, so every reference to an object is == to every other. A cloned reference controls the same object, with the same properties, children and events, but it is not equal to the ordinary reference. Code that collects Instance references, such as a table keyed by Instance or an equality check, does not recognize it.
Example
local players = game:GetService("Players")
local ref = cloneref(players)
print(ref == players)
print(ref.Name, ref.LocalPlayer)
print(compareinstances(ref, players))
Notes
- Use
compareinstancesto check whether two references point at the same object.
These are Game executor contracts. Check build requirements and session lifetimes before using them.
