Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Is it possible to make functions on instances?

Asked by 8 years ago
Edited 8 years ago

Pretty much what I wanna do is be able to give a Part it's own function.

for example: workspace.Part:Nil()

or

workspace.Part:Boom()

Is there anyway I can attempt this? I've tried just doing this:

function Item:Nil()
Item.Parent = nil
end

(I didn't think that'd work but I tried)

This might not be possible. But if there is anyway to make a "metatable" for a part then maybe it is possible (doubt it) Thank you for the help. If you can't find any way to do it that's fine.

1 answer

Log in to vote
0
Answered by
RubenKan 3615 Moderation Voter Administrator Community Moderator
8 years ago

This isn't possible. Roblox doesn't allow us to customly bind functions to objects. If you were using a more open engine (f.i. Unity / Unreal Engine), you could implement those custom functions.

For your Objet:Nil() function, you should use:

function Nil(Object)
    if Object then
        Object = nil
    end
end

Nil(MyObject)

Or just the simple one line: Object:Destroy()

For your Object:Boom() function, you can make

function Boom(Object)
    if Object:IsA("BasePart") then
        Instance.new("Explosion",game.Workspace).Position = Object.Position
    end
end

Boom(MyObject)

This will create an explosion at the Position of MyObject.

0
I know how to make the functions normally. I just wanted to know if it was possible to directly set it to an object fireboltofdeathalt 118 — 8y
0
Well, as i said in here, its not, unfortunatly. RubenKan 3615 — 8y
Ad

Answer this question