Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Adding a :Function() to the game instance?

I want to do something like this:

game:DeleteSomeObject( workspace.Part )

I was wanting to know if this is possible or not if so it would be helpful for me. I would like to say yes I know how to destroy a part this is just a example

2 comments

0

partname:Destroy()

0

Maybe with the use of OOP?

1 answer

there is no built-in way to actually add methods to an instance, but you can use instance wrapping to fake adding methods to an instance

although, instance wrapping is kind of hacky, and wrapped instances can't be accessed in other scripts unless you make something (e.g. a module) that manages them

you can find a pretty detailed tutorial on it here https://devforum.roblox.com/t/wrapping-with-metatables-or-how-to-alter-the-functionality-of-roblox-objects-without-touching-them/221611

note that you'll need at least a somewhat decent understanding of metatables to use wrapped instances

This discussion is preserved as it was. New answers, comments, and votes are closed.