Tutorial namecall metamethod (for dumbs)

yes I did that because I learned namecall metamethod in like 1 week and I still don’t know __index and __newindex. Those are easy but I am dumb so me making a tutorial for a big important metamethod to dumb people like me there is very much tutorials about that but they are like gods language for dumb people like me

ok so metatables are tables and they can store “metamethods” in it
metamethods are variables in metatable and they are usually functions
this tutorial is about __namecall metamethod which is big important
(btw: lua doesnt support __namecall its roblox only)

metatables are hidden tables, and can be accessed only with getmetatable()
but, we will use our exploit’s special function, getrawmetatable() or debug.getmetatable()

why?
because if metatable have a __metatable metamethod, when we will try to access metatable, instead of real metatable, getmetatable() will return __metatable metamethod.

ok let’s start with getting metatable

roblox locks metatables for instanced on datamodel, so we need to get it with using a special function

local metatable = getrawmetatable(game)

if setreadonly then
setreadonly(metatable, false)
elseif make_writeable then
make_writeable(metatable)
end

with this code, we grabbed the metatable and made it writeable.
now we need to save a backup for metamethod so we will return it later
(for dumber than me language: basically we are putting a code before the real function)

local backup = metatable.__namecall 

--[[
now, we have a backup for real function of __namecall metamethod so we will make the __namecall metamethod return the backup later so we wont change the whole function and we will make it just put a code before the real work of function(backup is function's real code)
]]--

now all we had to do was follow the damn train cj
all we have to do is

metatable.__namecall = function(self, ...) 
local method = getnamecallmethod() 

-- this function gets the method, ex: :Kick(), :FireServer(), :InvokeServer()

local arguments = {...}
-- do something

return backup(self, ...) 
--[[ now we returning the real function so function will continue working normal but it have the code that we put ]]--
end

what you can do with __namecall?
remote spies
some shit for games because you can get after : functions like :Kick()

an example remotespy:

local metatable = getrawmetatable(game)

if setreadonly then
setreadonly(metatable, false)
elseif make_writeable then
make_writeable(metatable)
end

local backup = metatable.__namecall
 
metatable.__namecall = function(self, ...) 
local method = getnamecallmethod()
local arguments = {...}

if method == "FireServer" then

print("hi a remote event fired")
print("location: "..self:GetFullName())
print("arguments:")

for i,v in next, arguments do
print(i,v)
end

elseif method == "InvokeServer" then

print(“hi a remote function invoked”)
print("location: "…self:GetFullName())
print(“arguments:”)

for i,v in next, arguments do
print(i,v)
end
end

return backup(self, ...)
end

yes I hope you learned what is the namecall metamethod and metatables
If you are all ultra super dumber than me then im sorry

If I’m wrong about something please tell me and I will edit it
thanks
(applebee tell me if im wrong ok u pro me noob)
now bye dats all

oh and if some of u pro scripters can teach me __index and __newindex i can translate it to dumbs language and make a tutorail about it
~edited by @applebee for some grammar fixes and formatting