Instances are Tables?

Look at this code:

local Part = Instance.new("Part", workspace) --the part

local Table = setmetatable({}, {__index = Part}) -- How?
Table.Lol = "Lol"

print(Table.Position, Table.Lol)

0, 0, 0  Lol --Output

So parts are tables? so that means that any instance is basically a table that has a physical form attached to it somehow?

which also means that services are classes with methods?

if so then is the code above a bad practice and shouldn’t be used?

and does it have any bad effect on performance?

the reason I’m asking this is that I’m making a weapon class and wanted a way to add functionality to an instance so it can Fire, reload…etc

thx for any help, really appreciate it

They are userdatas, not tables. Try =type(Instance.new("Part")) in the command bar – you will see userdata in the output. It’s just invoking the __index metamethod of the instance.

2 Likes

Didn’t understand what you mean by invoking the __index?

i thought __index can only refer to a table?

wouldn’t typeof() print something else?
because type() is lua specific

Yes, that is why I used type and not typeof

Apparently not

2 Likes

I will be using that Code i showed you to make a weapon system so does it have any effects on the server?
i’m talking about performance

1 Like

_index can apply to pretty much anything. You can even set it to a function as long as it returns something. You shouldn’t see any substantial difference in performance if you did use that pathway. Having said that it’s a very weird way of accessing the properties of an instance.

https://www.lua.org/pil/13.4.1.html

1 Like

Really appreciate this, that helped, im using it for Different Purposes than ususal that why it looks weired but if you saw the code it will make a lot of sense.

1 Like