hookmetamethod
Hooks a specific metamethod on an object's metatable.
function hookmetamethod(objectobjecttable | userdataThe object whose metatable contains the metamethod to hook.: table, methodmethodstringThe metamethod name, e.g. "__namecall", "__index", "__newindex".: string, hookhookfunctionThe replacement function.: function): functionfunctionA trampoline to the original metamethod implementation.Usage
Intercept __namecall on game
local origNamecall
origNamecall = hookmetamethod(game, "__namecall", function(self, ...)
local method = getnamecallmethod()
if method == "FireServer" then
print("RemoteEvent fired:", ...)
end
return origNamecall(self, ...)
end)