#making methods for instances made with the Instance constructor

19 messages · Page 1 of 1 (latest)

hazy elm
#

ok so ik how to make methods for stuff like keywords or how can i say, "default" classes idk(for example ik how to make methods for Instance or game:GetService("Players") or even for a specific part in the workspace):

--module script
local custom_instance_constructor = {}

function custom_instance_constructor.poop(obj)
    obj.Name = "poop"
end

return setmetatable(custom_instance_constructor, {__index = Instance})

--server script
local Instance = require(module)
Instance.poop(workspace.Part) --works fine

, but how would i make methods or properties for classes made from the Instance constructor?
i tried doing this:

local custom_part = {}

function custom_part:poop()
    self.Name = "poop"
end

return setmetatable(custom_part, {__index = Instance.new("Part")})

but then i just cant do this:

local Instance.new("Part") = require(module) --errors
or
local Part = Instance.new("Part") --just makes a part
or
local Part = require(module)
gaunt forum
#

@hazy elm

#
--// Roblox services.
local ReplicatedStorage = game:GetService("ReplicatedStorage")

--// Modules
local gameUtils_Folder = ReplicatedStorage:WaitForChild("gameUtils")
local Janitor = require(gameUtils_Folder:WaitForChild("Janitor"))

--// Object
local Template = {}
Template.__index = Template

function Template.new() 
    local self = setmetatable({ 
        
        _janitor = Janitor.new()
        
    }, Template) 
    
    return self 
end

function Template:Destroy() 
    
    if self._janitor then
        self._janitor:Destroy() 
        self._janitor = nil
    else
        warn("Attempt to destroy object 'Template' when it was already destroyed.")
    end
end

return Template```
#

this is my class template

#

press ctrl + F in the script, type in Template and then replace it with whatever u wanna name it

split sleet
split sleet
#

a module where you can add custom properties, methods, and events to instances

hazy elm
#

no

#

i already know how to do thay

#

that*

split sleet
#

aight mb

#

are you looking for a custom Instance.new() that adds more events/properties/methods in it?

hazy elm
#

no

hazy elm
split sleet
hazy elm
#

i actually idk

#

maybe