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

Is it possible to make functions on instances?

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 comment

1 answer

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.

2 comments

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

0

Well, as i said in here, its not, unfortunatly.

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