You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i was wondering if it is possible to have userdata that inherits another userdata with the luau feature.
i've already tried setting __index to return the super class. i also tried returning the metatable of the super, though i wasn't able to due to the metatable being wrapped around UserDataMetatable.
my goal is to have two types named Instance and WorldInstance, where Instance has a field named Name and WorldInstance has a field named Position. the user would then be able to access the Name field from an instance of WorldInstance. would that be possible?
that does work, though the only issue that i have is that if the key doesn't exist, it would return nil instead of giving me an error. this also makes it unknown if its a field with a value of nil, or if the field doesn't exist.
since i can't find any method for checking if a key exists, is there another way make it return an error for when the parent field doesn't exist?
Activity
khvzak commentedon Feb 9, 2026
You can do something like:
SDFTDusername commentedon Feb 10, 2026
that does work, though the only issue that i have is that if the key doesn't exist, it would return
nilinstead of giving me an error. this also makes it unknown if its a field with a value of nil, or if the field doesn't exist.since i can't find any method for checking if a key exists, is there another way make it return an error for when the parent field doesn't exist?
khvzak commentedon Feb 10, 2026
you sure? Accessing
WorldInstance.NonExistentraise an exceptionruntime error: attempt to get an unknown field 'NonExistent'.This can happen though for static fields. In Lua
niland non-existent is the same (for example you cannot have a table with a key set tonil).