How do you hook functions?

After using a framework in C# to patch functions, I was wondering if this is possible to do on Roblox

In case you don’t know, patching functions (at least to what I know) is a way to do something before/after a certain function is ran, change the return values of functions, changing the parameters of functions, etc

You can also look at patches of a function

I did some research and I found out that vanilla Lua supports this, so that’s how I got the idea that Roblox can support this

The way that I used to patch in C# would be the following

[HarmonyPatch(typeof(Class), nameof(Class.Method))]
        public static class ExamplePatch
            public static void Postfix/Prefix()
               // code here

If there’s a way to do something like this, can you please tell me the method? Thanks in advance


Hooking functions is only possible through the use of an exploit. Exploits grant you a lot more freedom then Roblox itself when it comes to writing scripts. Exploits are basically able do whatever they want to the client, which includes hooking functions which can be a major problem for developers, so allowing this to be an official feature would pose as a security risk.

Exploiters can also check when events are fired on the client through the use of metatables and metamethods (which I believe is what you mean when referring to “patching” functions?) which is also problematic for developers. An example of this is firing a remote, where an exploiter can detect when the remote is fired and then change any arguments passed to the server from the client.

you could possibly do it with a “fake” environment with setfenv and warn the incoming args when a function is called but this would only work on functions within the script
like tick() or time()