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 create custom object functions?

By object function I mean the functions that you call with :. For example, model:MoveTo().

I am creating a script that shortens functions (WaitForChild = wfc), so I wanted to know if you could make custom object functions. If not, I would have to keep using _G.funcName() (which sucks) instead.

Thank you!

~TDP

2 comments

0

You should look into module scripts. Additionally, you can define a parameter using : with any function, it's not for built-in functions alone.

0

I think I've seen this done before, but a long time ago. I would not be able to look it up easily.

1 answer

I found something in the wiki that may help. I heard of this before and went to the wiki. I found this:

tab = {}

function tab:method( args )
	print( "I'm a method from " .. tostring(self) .. " with args " .. tostring( args ) )
end

Now if I call this function like this:

tab:method("Hello there!")

It'll print this:

I'm a method from table: 0x16082c60 with args Hello there!

If you click the link above you can find out more about functions.

I should also add in that this will not attach to any object. You must use _G. But you could make a table in there to make a method like this:

_G.tab = {}

function _G.tab:method(ARGUMENTS_GO_HERE)
	--Your code goes here
end

and then call it like this:

_G.tab:method(ARGUMENTS_GO_HERE)

Good luck on your future Scripting Adventures! ~lightpower26

2 comments

0

I don't think this is what he was intending to accomplish. I think he's wanting to achieve more along the lines of Instance.new('Part',workspace):InsertFunctionNameHere() and having different functions he makes, and not just Clone(), Destroy(), FindFirstChild() etc.

0

Thank you guys for trying :/

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