cloneref
Returns a safe reference clone of an Instance to defeat weak-table detections.
function cloneref<T>(object: T & Instance): TSynopsis
How it works
Creates a new
userdata wrapper that points to the same underlying Roblox C++ instance as the original. The two wrappers have different Lua identities — rawequal(original, clone) returns false — but every property read/write and method call on the clone affects the same internal object.Anti-detection use
Anti-cheat scripts may hold a reference to a sensitive InstanceInstanceThe base class for all Roblox objects (Parts, Models, Scripts, GUIs, etc.). Instances form a tree hierarchy (the DataModel). In Luau, they appear as userdata with shared metatables. (e.g., a RemoteEventRemoteEventA Roblox Instance for one-way client-server communication. :FireServer() sends data from client to server; :FireClient() sends from server to client. Commonly intercepted by executor hooks on __namecall.) and check
rawequal(stored, suspect) to see if your script obtained the same reference. cloneref() breaks that check because it returns a distinct userdataUserdataA Luau type for C-allocated memory blocks. Roblox Instances, Vector3s, CFrames, and other engine types are userdata with metatables providing their API. Cannot be created from Luau directly. even though both refer to the same C++ object. Use compareinstances() to test pointer equality instead.Usage
Safe access to LocalPlayer
local Players = game:GetService("Players")
local safe = cloneref(Players.LocalPlayer)
print(safe == Players.LocalPlayer) "cc">-- false
print(safe.Name) "cc">-- your username
print(compareinstances(safe, Players.LocalPlayer)) "cc">-- trueParameters
object Instance The Instance to create a safe reference from.
Returns
Instance A new reference to the same Instance. Not == to the original, but compareinstances() returns true.
Anti-detection use case
Weak tables store Instance references. cloneref gives you a different pointer to the same object so the game cannot track you through its weak table.