getnamecallmethod

Gets the method name being called in a __namecall hook.

Syntax

getnamecallmethod() -> string?

Returns

TypeDescription
string?The method name inside a __namecall hook, otherwise nil

Description

getnamecallmethod returns the name of the method that invoked __namecall. When called outside a __namecall hook, it safely returns nil.

Example

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

    if method == "Kick" then
        return -- Block kick
    end

    if method == "FireServer" then
        print("FireServer called on:", self)
    end

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

Common Methods to Hook

MethodObjectDescription
FireServerRemoteEventClient to server communication
InvokeServerRemoteFunctionClient to server with return
KickPlayerKick the player
DestroyInstanceDestroy an instance
GetServiceServiceProviderGet a service

Filtering Example

local blockedMethods = {"Kick", "Ban", "Disconnect"}

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

    if table.find(blockedMethods, method) then
        warn("Blocked:", method)
        return
    end

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

Notes

  • Only works inside __namecall hooks
  • Returns nil outside a __namecall hook
  • Case-sensitive