hookmetamethod
Hooks a single metamethod on an object's metatable and returns the original. A shorthand for getrawmetatable plus setreadonly plus hookfunction.
Signature
hookmetamethod<A..., R...>(object: Instance | table, method: string, hook: (A...) -> R...): (A...) -> R...Parameters
objectInstance | tableThe object whose metatable is patched.
methodstringThe metamethod name, such as "__index" or "__namecall".
hook(A...) -> R...The replacement metamethod.
Returns
function
Example
local old
old = hookmetamethod(game, "__namecall", function(self, ...)
if getnamecallmethod() == "Kick" and not checkcaller() then
return
end
return old(self, ...)
end)