Are you able to clone modules and edit them at runtime?

i’m trying to make it easier to add hats to my game by creating the hat and creating a config module for it.

according to print statements, it works but the module that is cloned and edited still says 0 when opening the module.

is this something that isn’t possible to do? or does anyone know easier ways of doing this task?

1 Like

Only plugins are able to modify the source code of ModuleScripts, LocalScripts and Scripts

From what I can understand, creating a base class that all hats inherit from (like how Parts inherit from the BasePart class), then adjusting the configuration according to the type of hat would work best in a case like yours

I recommend you familiarize yourself with object-oriented programming and metatables:


@lilsquish08 Here’s an example of how the module will need to look like:

local BaseHat = {
	Color = Color3.new(0, 0, 0),
	Name = "Hat",
	Price = 100
}
BaseHat.__index = BaseHat

local Hat = {
	new = function()
		return setmetatable({}, BaseHat)
	end
}

return Hat

And this is an example of how to create and configure a new hat using the module (tested using a Script in ServerScriptService):

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Hat = require(ReplicatedStorage.Hat)

local topHat = Hat.new()
topHat.Color = Color3.new(1, 1, 1)
topHat.Name = "Top Hat"
topHat.Price = 300

print(topHat)
2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.