local Car = {}
Car.__index = Car
function Car.new(carColor)
local self = {}
self.color = carColor
return setmetatable(self, Car)
end
function Car:GetColor()
return self.color
end
local carObj = Car.new("blue")
print(carObj:GetColor()) -- Returns blue
I’m pretty sure default roblox instances and such are read-only, however, you can make wrapper classes. Such as
local inst = Instance.new("IntValue")
local IntWrapper = {}
function IntWrapper.new(objToWrap)
local self = {}
return setmetatable(self,
{__index = function(obj, key)
return IntWrapper[key] or objToWrap[key]
end})
end
function IntWrapper:GetValue()
return self.Value
end
local int = IntWrapper.new(Instance.new("IntValue"))
print(int:GetValue(), int.Value) -- Both return 0, as that is the default value for IntValue's