EzWrapper - Add custom functions, properties, and signals to objects!

Introduction

I lately wanted a way to add custom functions and properties to my Roblox objects without inconvenience so I created this simple project! All you need to do is insert this code above all of your scripts:

local ezWrapper = require(...) --> path here
ezWrapper:Setup()

It will then automatically wrap every instance from that point forward in a script without you having to even think about it!

Pros

  • Easy to use
  • Increased versatility of all instances
  • Works across scripts
  • Even wraps objects passed in signals like ‘DescendantAdded’

Cons

  • Not as fast as regular objects, but that’s to be expected
  • Doesn’t work across the client / server boundary naturally

Documentation

Instances

These methods work across all instances that come into the script’s environment.

:SetCustomProperty(‘name’,‘value’)

Arguments: string, any (table, color, string, number, and more!)
Description: Sets a custom property for the specified instance that can now be indexed directly as a priority
Sample code:

object:SetCustomProperty("Damage",15)
print(object.Damage) --> 15

:SetFunction(‘name’,‘function’,‘methodCheck’)

Arguments: string,function,boolean
Description: Sets the specified method on the object, similar to the :SetCustomProperty but can check for if it’s called as a method internally
Sample code:

object:SetFunction("GetData",function(argument)
    return({name = "hello",calledWith = argument})
end,true)
print(object:GetData("test")) --> {name = "hello",calledWith = "test"}

:NewSignal(‘name’)

Arguments: string
Description: Creates a custom signal that can be connected to for the object
Returns: <signal>
Sample code:

local signal = object:NewSignal("Hello")

signal:Connect(function()
    print("do something cool here")
end)

object.Hello:Fire()

:GetRaw()

Arguments: <N/A>
Description: Returns the raw object instance if you need it for some reason
Returns: Instance
Sample code:

object:GetRaw()

:GetCustomProperties()

Arguments: <N/A>
Description: Returns all custom properties set as a dictionary
Sample code:

object:SetCustomProperty("test","hi")
print(object:GetCustomProperties()) --> {test = "hi"}

:GetCustomFunctions()

Arguments: <N/A>
Description: Returns all custom functions in a dictionary similar to the above
Sample code:

object:SetFunction("Get",function()
    print("cool")
end)
print(object:GetCustomFunctions()) --> {Get = <function>}

Credits

Where do I get it?

Disclaimers

  • I made this as a learning experience and I am open to constructive criticism that’s helpful to making my code more efficient as a developer.
  • I don’t expect this to work 1000% absolutely flawlessly and I expect bugs but I haven’t had any before releasing and I hope you can discover and report any to me!

Polls

Would you use this?
  • Yes
  • No

0 voters

If you did use this, how helpful would it be to you?
  • 0
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

0 voters

18 Likes

This looks absolutely insane! I’ve been trying to add custom functions to objects for a while now but nothing really worked, so this will help a lot! Thank you so much!

1 Like

You’re very welcome, if you experience any issues or have questions please don’t hesitate to contact me!

1 Like

The following is meant as constructive criticism. I like the idea, but unfortunately, this is completely unnecessary.

All of the methods provided require you to wrap each instance you want to use with the new methods when you could easily use built in things like Attributes and BindableEvents and local functions to accomplish the same thing. This seems to just be wasting memory.

1 Like

I am aware of this, I just don’t like the way they look in code because this looks nicer to me. It’s not meant to be scaled onto a map with like 200,000 parts each with advanced functions but more like having effects to add to parts easily such as:

part:TweenTransparency(1)

Thanks for the input! I wonder how I can make it more memory efficient though.

I’m guessing it just adds a value to the object?

What do you mean? It uses tables because I think values would take way more memory than this already would.

So youre basically storing the part and the value in a table. I don’t think it’s that special

Attributes are faster anyway

You can’t store functions, signals, or tables in attributes. Maybe you should read the whole post.

modulescripts as configuration works well.

wait… when i checked the vote for “Would you use this?”, the percentage for the answer “NO” was 53% and the percentage for the answer “YES” was also 53%… idk what is wrong here

dude how the **** do you store functions, arrays, tables/dictionaries, or signals in attributes???

It takes a bit of time to recalculate your vote into it.

I mean it’s still messed up for me lol

This forum has a bit of a weird poll calculation. When you insert your vote, it calculates your vote into the option you chose, but it takes some time to calculate the other options.

Interestingly I checked it out and if you plug in the ‘total votes’ instead of ‘voters’ for the percentage calculation it gives the correct amount, but if you plug in for ‘voters’ it’ll give you the wrong numbers.

Example: 9 people said yes, 7 said no
The poll has 15 votes apparently when 9 + 7 = 16 but it also says 16 total votes

(9/15)*100 = 60
(7/15)*100 = 46.66…

60 + 46.66 = 106

But

(9/16)*100 = 56.25
(7/16)*100 = 43.75

43.75 + 56.25 = 100

Very weird, Discourse is wilding rn

oooh got it now thx :slight_smile: ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎ ‎‎‎

Bindableevent s + modulescript s

:Hugelaughomg: