ReferenceClosures

checkcaller

Tells a hook who called it: your own script, or the game.

Syntax

checkcaller() -> boolean

Also available as

check_caller

Returns

TypeDescription
booleantrue when the function was called from code you ran through Apex, false when the game called it.

Description

Apex decides by the calling thread's globals. Code whose environment leads back to the executor environment counts as yours, and so do functions your script connected to signals, even when the engine later runs them. Everything else, including the game's LocalScripts, ModuleScripts and CoreScripts, counts as the game.

The usual use is inside a hookmetamethod or hookfunction hook, where you want to change what the game sees but leave your own calls alone.

Example

local old
old = hookmetamethod(game, "__namecall", function(self, ...)
    if not checkcaller() and getnamecallmethod() == "Kick" then
        return nil
    end
    return old(self, ...)
end)

print(checkcaller())

Notes

These are Game executor contracts. Check build requirements and session lifetimes before using them.