Custom Class Module v1

download | source

This is a module which allows you to define existing objects as classes and set default properties for them and more (see API below)


Global functions

  • ClassModule()

    ClassModule(className, searchIn?: Object) -> class

    looks for an object in a specified container
    and caches a custom class, if the searchIn parameter is not specified it will look in the Object_Container defined in the module

  • Name, Parent) -> new instance Class
    cloned to the specified parent

    if no Parent argument is supplied then the Parent will be the DefaultParent defined in the module

Global Methods

  • Class:SetProperties(Properties: dictionary)

    takes a dictionary of properties and values and sets the custom class’ properties so that whenever or from wherever is called, the object created retains the custom set properties.

  • Class:DestroyAll()

    destroys all existing instances of the Class.
    StoreObjects (in the module) must be set to true for this to work, enabled by default.

  • Class:GetObjects()

    returns all objects of the Class this function was called on

General Usage


pseudo code:

    local CustomClass = require(game.ServerScriptService.ClassCreator)

    local part = CustomClass("part") --> new class called 'part'
    local newPart  = CustomClass("newPart")

    local part1 ="part1") -- part called "part1" is created, parented to workspace by default
    part1.Anchored = true -- index and alter properties as normally"part")"new part", workspace.Model) -- created under workspace.model

    local properties =
                       {Anchored = true;
                        Color = Color3.fromRGB(33,255,49);
                        Position =,0,40) }
    part:SetProperties(properties) -- future parts created using will have the above properties"green part")  --> this part has all of the properties defined in the above dictionary

    print(#part:GetObjects()) --> 3

    part:DestroyAll() --> all objects of class destroyed

This is not limited to parts, you can use your own models etc. too.

This module prevents the need to define objects’ properties separately each time, as :SetProperties() applies all the properties to the part contained, you could use this to set different properties instead of changing the properties each time you clone the instance separately.

You can use Class:DestroyAll() to destroy all objects of a class in the game, for objects created through
Require the module on the Client so that an object’s properties are different for every client.

credit to @ReturnedTrue for some suggested functions.

do respond with any suggestions so I can implement them, or bugs if they exist


Helpful, thanks
(30 characters)

1 Like

I’ll consider installing it, thanks!

1 Like

Please choose one

    • This resource was useful to me
    • more features would’ve made it better
    • not useful to me, but good work

0 voters

editing the original post caused the previous one to reset

1 Like