Hi,
So currently I’m trying to script a weapon system utilizing OOP (or just Object Oriented Programming). But while creating a class for a weapon, the Attributes meant to be used for self
is returning nil
values instead.
While printing the contents, it returns {}
instead of the Class.
Script Contents / Hirearchy
Module:function utl.new(Tool: Tool, Config: Configuration)
local self = setmetatable({}, { -- creates self
__index = item;
__newindex = function(t, i, v)
if not Config:GetAttribute(i) then return end
Config:SetAttribute(i, v)
end;
});
self.Tool = Tool; -- basic stuff
self.Handle = Tool.Handle;
self.Config = Config;
for i,v in Config:GetAttributes() do -- Point of error / where everything else is added
self[i] = v;
end
return self; -- suppsoed to return self and its contents
end
Server:
local ReplictedStorage = game:GetService(“ReplicatedStorage”);
local Mod = require(ReplictedStorage.Mod);
local Tool = script.Parent
local Config = Tool.Config
local Weapon = Mod.new(Tool, Config); -- Class created here
print(Weapon); -- where contents check is
Weapon:Setup() -- unimportant for now
What could be the issue here?