local Template = require(script.Parent.Template)
local Data = {}
Data.__index = Data
function Data.new()
local self = setmetatable({}, Data)
self.Template = Template
return self
end
function Data:setValue(valueName, value)
local findValue = self.Template[valueName]
if findValue then
findValue += value
end
end
function Data:subValue(valueName, value)
local findValue = self.Template[valueName]
if findValue then
findValue -= value
end
end
function Data:mulValue(valueName, value)
local findValue = self.Template[valueName]
if findValue then
findValue *= value
end
end
function Data:divValue(valueName, value)
local findValue = self.Template[valueName]
if findValue then
findValue /= value
end
end
function Data:getTemplate()
return self.Template
end
function Data:remove()
table.clear(self)
setmetatable(self, nil)
end
return Data
Use the metamethod __newindex. Here is an example taken from a post on how it would work:
--[[
We will be indexing surfaceTable the whole time,
which will stay empty.
]]
local surfaceTable = {}
--[[
Proxy table is going to be hidden, but will actually reflect
all the changes. This table will be updated each time.
]]
local _mainTable = {}
setmetatable(surfaceTable, {
__index = function(self,key)
print("Key number ".. key .." was accessed.")
return _mainTable[key] -- We return the key from proxy table.
end,
__newindex = function(self,key,value)
print("Key number ".. key .. " was updated. New value: ".. (value or "nil"))
_mainTable[key] = value -- Now we update our proxy table.
end,
})
Here’s the replacement for table.insert and table.remove (__newindex does not work with these methods in the Lua version Luau is based of).