local part = Instance.new("Part",workspace)
local function WrapThisPart(block)
local properties = {}
local metamethod = {}
properties.Speed = 20
properties.Height = 2
metamethod.__index = block
function metamethod.__newindex(self,index,value)
properties[index] = value
end
return setmetatable(properties,metamethod)
end
local itemWithWrapper = WrapThisPart(part)
print(itemWithWrapper.Speed) -- returns 20
print(itemWithWrapper.Weight) -- error
Hi everyone,
Im having trouble trying to call the meta methods on the code above. I can call the values that are already defined in properties, however, the metamethod is not executed when i call a variable that is not defined.
I also dont know how to call the new index function. How would i be able to do that?
Thanks

1 comment
Very helpful thank you