function DataMetatable.new(name, save)
if type(name) ~= "string" then return end
local self = setmetatable({}, DataMetatable)
self.Name = name
print(self.Name)
for _type, value in pairs(save) do
self[_type] = value
end
return self
end
Both printed for me as non-nil values, there must be something wrong with the second argument supplied or something.
DataMetatable = {}
function DataMetatable.new(name, save)
if type(name) ~= "string" then return end
local self = setmetatable({}, DataMetatable)
self.Name = name
print(self.Name)
for _type, value in pairs(save) do
self[_type] = value print(self[_type])
end
return self
end
DataMetatable.new("str", {a = "b", b = "c"})
local DataMetatable = {
__newindex = function(_table, key, value)
print(key, value)
if key == "leaderstats" then
pcall(function()
Players[_table.Name][key].Value = value
end)
end
end
}
function DataMetatable.new(name, save)
if type(name) ~= "string" then return end
local self = setmetatable({}, DataMetatable)
self.Name = name
print(self.Name)
for _type, value in pairs(save) do
self[_type] = value
print(self[_type])
end
return self
end
apparently it prints nil when i put in metamethods, do you know why?
You’re overriding the __newindex metamethod, which determines what behavior yourTable[something] = whatever does. Since you aren’t ever actually having the value be set in the __newindex function, it’s still nil.
The reason is because you’re using it unnecessarily but more importantly because __newindex will trigger every time you assign a new index, so unless you set it to return a non-nil value it’ll obviously be not-defined whenever you call t[index] = v.
I’m not sure what the issue is, but try this
EDIT: oh well someone answered it for you
function DataMetatable.new(name, save)
if type(name) ~= "string" then return end
local self = {}
setmetatable(self, DataMetatable)
self.Name = name
-- stuff
I have no idea if this would work or not, but give it a try ¯_(ツ)_/¯