Skip to content

getnamecallmethod

This function must be called from within a __namecall metatable hook, otherwise it will return nil.

getnamecallmethod returns the name of the method that invoked the __namecall metamethod.

When used inside a hookmetamethod hook targeting __namecall, it will attempt to retrieve the method being called (e.g. InvokeServer).

When used outside of said hook, this function will safely return nil.

function getnamecallmethod(): string?

Parameters

Parameter Description
(none) This function takes no parameters.

Example

Disallowing the usage of game:service()
local refs = {}

refs.__namecall = hookmetamethod(game, "__namecall", function(...)
    local self = ...
    local method = getnamecallmethod()

    if self == game and method == "service" then
        error("Using game:service() is not allowed.")
    end

    return refs.__namecall(...)
end)