Volt

getcallingscript

Returns the script that called the current function.

Syntax

getcallingscript() -> LocalScript | ModuleScript | nil

Returns

TypeDescription
LocalScript or ModuleScript or nilThe calling script

Description

getcallingscript returns a reference to the script that invoked the current function. This is useful in hooks to identify which script triggered the call.

Example

local oldPrint = print
print = function(...)
    local caller = getcallingscript()
    if caller then
        oldPrint("[" .. caller.Name .. "]", ...)
    else
        oldPrint("[Unknown]", ...)
    end
end

-- When a game script calls print, it shows which script

In Metamethod Hooks

local oldNamecall
oldNamecall = hookmetamethod(game, "__namecall", newcclosure(function(self, ...)
    local caller = getcallingscript()
    local method = getnamecallmethod()

    if caller then
        print("Script:", caller:GetFullName())
        print("Method:", method)
    end

    return oldNamecall(self, ...)
end))

Notes

  • Returns nil if called from volt (not from a game script)
  • Useful for filtering hooks based on the calling script
  • Works in hooked functions and metamethods

On this page