Create custom functionalities on Roblox Objects! Using methods.
Motivations
I made this because I wanted to create a recreation of the MT_Api made by rain back in 2017 linked here.
How to use
To use CustomMethods Copy this and Paste it on top of your script.
local CustomMethods = loadstring(game:HttpGet('https://raw.githubusercontent.com/Perthys/CustomMethods/main/main.lua'))()
We are going to make a simple method globally called
:PrintFullName()
using theCreateGlobalMethod()
function.
local Namecall = CustomNameCalls:CreateGlobalMethod(":PrintOutFullName()", function(self, ...) -- Please Note : and () are optional and you can use the direct name.
return print(self:GetFullName())
end)
-- This method will now work for every single object in the game.
game.Players.LocalPlayer:PrintOutFullName() -- Output: Players.AltAccountReal
It's that simple!
How To Remove
You can easily remove the method by calling the returned function.
local Namecall = CustomNameCalls:CreateGlobalMethod(":PrintOutFullName()", function(self, ...)
return print(self:GetFullName())
end)
Namecall()
game.Players.LocalPlayer:PrintOutFullName() -- Output: nil
Creating Methods for specific Instances
You can also create methods for Specific Instances with the
CreateInstanceMethod()
function
local Namecall_2 = CustomNameCalls:CreateInstanceMethod(game.Players, "Hello", function()
return "Goodbye"
end)
print(game.Players:Hello()) -- Output: Goodbye