I’m using a module script with a function to create a metatable with the variable self. I do this both on the client and server, the problem is that, once I print the return of the function on the server it returns the correct values but if I do it on the client it for some reason returns the functions within the module script.
function Framework:Initialize(WeaponName, Char)
local Data = require(script.Support.WeaponData)[WeaponName]
if RunService:IsClient() then
local self = setmetatable({}, Framework)
for i,v in pairs(Data) do
self[i] = v
end
self.Character = Char
self.Combo = 1
self.Name = WeaponName
print(self)
else
for i,v in pairs(Data) do
self[i] = v
end
local Model = script.Assets[WeaponName].Weapon:Clone()
Model.Parent = Char
local BackWeld = Instance.new("Motor6D")
BackWeld.Parent = Char.Torso
BackWeld.Part0, BackWeld.Part1 = Char.Torso, Model.PrimaryPart
BackWeld.C0 = Data["BackPos"] * Data["BackRotation"]
BackWeld.Name = "WeaponWeld"
BackWeld.C1 = CFrame.new(0,0,0)
end
print(self)
return self
end
Here’s the 4 prints
Print no.1 is done in the server (when I print self before returning self, this one works fine)
Print no. 2 is done on the client (the first time I print self, which returns the values I’m expecting)
As for print no.3 and no.4, they are ‘print(self)’ before the return on the module and once I attempt to print the return of the module on the client. Both of which return the functions within the module script
I really don’t get why on the client, it works the first time I print self, but on the second time I do it, it doesn’t work.