So I'm messing around with metatable's, i understand how setmetatable and __index and __newindex works, but i don't understand inheritance and multiple inheritance yet quite well.
My Problem: I try to get the variable 'h' but it prints nil, everything else is fine, what am i doing wrong here? How can i have nested metatables connected to each other, like fallback when one fails it goes to other.
Here's Code:
local Window = {
ClassName = 'ScrollingFrame',
Size = UDim2.new(0,0,0,0),
CursorColor3 = Color3.fromRGB(255,255,255),
}
Window.__index = Window
Window.metatable = {}
Window.metatable.__index = {
getClassName = function(self)
return self.ClassName
end
}
setmetatable(Window, Window.metatable)
--I Can't to seem to get "h" variable from here for some reason?,Why?
Window.LockedProperties = {}
Window.LockedProperties.__index = {h = 999}
setmetatable(Window.metatable, Window.LockedProperties)
--Constructor
function Window.new()
return setmetatable({},Window)
end
local w = Window.new()
print(w.Size)
print(w.h)
print(w:getClassName())

4 comments
Your Example is printing out nil nil
I fixed it by putting (Window.__index = Window) after Window table
Could you please post examplewith __newindex where the Window.LockedProperties is locked i tried using __newindex but it throws error trying ot index "new" a nil value
Hm alright