Why this no work?

Im trying make a Module:Create instead of Instance.new because i seen a modulescript do it before but idk how

this is my code

local Module = {}
Module.__index = Module

function Module.new(name)
	local object = Module:Create(name, {
		Name = name,
		Parent = workspace
	})
	setmetatable(object, Module)
	return object
end
return Module

script

local Module = require(game:GetService("ReplicatedStorage").ModuleScript)

Module.new("Part")

please help me

1 Like

You haven’t made a Module:Create() function:

function Module:Create(name)
    local object = Instance.new(name)
    object.Parent = workspace

    return object
end

Also, there really is no need to make a function for this… since its built in

1 Like

This is way unnecessary and you should use Instance.new directly on the script/localscript to create anything

local part = Instance.new("Part",game.Workspace)
part.Name = "Part1"
1 Like

Neither did the modulescript I looked at

You cannot call an imaginary function. It must first be defined.

if youre trying to wrap an object (so you can add custom properties etc) then you could just store an instance in an empty tables index. (there is more stuff you can do to enhance this properly but i’ll show you the basics)

local Module = {}


function module.new(name)
    local object = {}
    object.CustomValue = "YAY A CUSTOM VALUE"
    
    --get instances properties/functions
    local content = {}
    content.__index = Instance.new(name)
    setmetatable(object, content)

    return object
end


return Module
local m = require(script.Parent)
local part = m.new("Part")

print(part.CustomValue) --> YAY A CUSTOM VALUE

if there is any typos, then im sorry. :stuck_out_tongue: