Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
0

Adding a :Function() to the game instance?

Asked by 8 days ago
Edited 8 days ago

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

0
partname:Destroy() raid6n 2290 — 8d
0
Maybe with the use of OOP? uhi_o 417 — 8d

1 answer

Log in to vote
0
Answered by
Elyzzia 1023 Moderation Voter
8 days ago

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

Ad

Answer this question