Say I had:
function PrintName(Input) print(Input.Name) end
And I wanted to use this as a method, like such:
game.Workspace.Part:PrintName()
Would I have to use the usual PrintName(game.Workspace.Part) or would that work?
It won't work. However, it is possible to create your own methods.
Sorry these people aren't really answering your question, I'll do my best attempt to do so.
You could give your parts and objects their own methods, to the point where you could literally write,
game.Workspace.Part:PrintName()
and get a result as expected, but it's honestly not worth it. It can be easily done however through the use of a custom environment. If you want me to, I can write something quick up for you explaining how to do it.
I see what you are asking.
What you want to do wouldn't be accomplished using new methods, but using parameters
.
To call your function, you can use the following:
PrintName(game.Workspace.Part)
For example, if you wanted to use that to print the name of all parts in a model, you could use the following:
for i,v in pairs(game.Workspace.Model:GetChildren()) do PrintName(v) end
That would print the name of every item in the model by calling the function PrintName
, setting its parameter to the item's name.