CustomInstance [V2.XX] - Add more properties and methods to Roblox Instances!

with this module you can add custom properties and methods to roblox objects, simply said: CustomInstance

image

Features:

  • Server->Client replication using BridgeNet2
  • GetPropertyChangedSignal can be used on custom properties
  • Add custom properties to objects
  • Add custom methods to objects

  • By editing this table inside the module, you can make classes inherit properties and methods from other classes

Creating Presets/Classes:

In this module, presets are the equivalent to roblox object classes (eg: Humanoid, BodyGyro and …), to create new ones all you have to do is go inside the module and find a folder called “Presets”
image

Ive already left 2 presets in there so you can duplicate those and adjust them to your needs

Download:

Roblox Library: CustomInstance - Roblox
Github: Releases · HighFlowey/CustomInstance · GitHub

API Document:

module.new(className: string, instance: Instance): CustomInstance

  • equivalent to Instance.new(className: string)

module.get(instance: Instance): CustomInstance?

  • returns class for requested object

Example:

-- Server --
local newClass = CustomInstance.new("Car") -- This is a custom class
newClass.Speed = 100
newClass.Name = "NewCar"
newClass.Parent = workspace

task.wait(5)

newClass.Speed = 50
-- Client --
local object = workspace:WaitForChild("NewCar")
local newClass = CustomInstance.get(object)

print(newClass.Speed)

newClass:GetPropertyChangedSignal("Speed"):Connect(function(old, new)
    print(old, new)
end)
3 Likes

added server-client replication :white_check_mark:.

1 Like

Why should we use this? Cant i just do

local ratatata = instance.new("humanoid")
ratatata.walkspeed = 90 

why use your model when we can do instance.new? or am i not understanding it

3 Likes

Why use this over binders?

3 Likes

humanoids dont have these… ignore thisss

1 Like

I honestly dont know what binders does but the point of this module is to replace attributes and keep my scripts consistent

object:SetAttribute("Money", object:GetAttribute("Money")+10)
object:SetAttribute("Money", 50)

object:GetAttributeChangedSignal("Money"):Connect(function()

end)
object:GetPropertyChangedSignal("Parent"):Connect(function()

end)
local class = Module.new(object)
class.Money += 10
class.Money = 50

class:GetPropertyChangedSignal("Money"):Connect(function()

end)
class:GetPropertyChangedSignal("Parent"):Connect(function()

end)
1 Like

Does performance take a big hit? Is this a zero-cost abstraction?

1 Like

at the start of the game:
image

5 seconds after the game starts (ignore the third one):
image

local started = os.clock()
workspace:SetAttribute("Something", 10)
print(os.clock()-started)

local CI = require(ReplicatedStorage.CustomInstance)
local class = CI.new(workspace)

local started = os.clock()
class.Something = 10
print(os.clock()-started)

its gonna get more optimized with the update that is gonna come out in the next 2-3 hours

1 Like

I updated the module to make it a tiny bit more optimized. (cant get any better than this)

1 Like

Important Update (v0.03):


I decided to rewrite the module and remove attribute support to improve performance

as you can see the new version has better peformance than attributes unlike the previous version:


image

it has all the features from v0.02 including server—>client replication


current limitations:

  • no support for tables
  • no server<—>client replication for functions yet
1 Like

Do a benchmark and get the 75th percentile of the results. This seems too quick to be true. Also a github repo would be nice.

1 Like

did another benchmark before closing my laptop which was 3 hours ago:

image-13

Is this the 75th percentile of many tests or is it a single test?

single test, i ran it multiple times and the performance was better than using attributes in all of them

just did a benchmark that gets 75th percentile of 20 results for each method
image

Summary

ignore dynamictables its another module that ive made

UPDATE:

  • added a cooldown to server-client replication to make the module usable in expensive loops!

now you can read the source code in this github repo:

NEXT UPDATE:

  • make indexing for properties atleast 2x faster

cant you just use a dictionary

well CustomInstance gives you a GetPropertyChanged signal and server->client replication so no you cant just use a dictionary if you want these features.

UPDATE

  • Improved performance

Setting properties:
image

Getting properties:
image

1 Like

Update 1.0:

  • Rewrote the whole module
  • BridgeNet2 Support (better server->client replication)
  • 2x slower than previous version, had to sacrifice a tiny bit of performance for better workflow but if you care about performance you can still get v0.5 from github’s releases page

I didnt do a lot of testings on this version so if lmk if you find any bugs :smile: