So I have a tool and a gun class with methods like :Equip() and :Unequip() like so, which i call in a regular script whenever the tool is equipped or unequipped.
local Gun = GunClass.new()
local Tool = script.Parent
Tool.Equipped:Connect(function()
Gun:Equip()
end)
Tool.Unequipped:Connect(function()
Gun:Unequip()
end)
But is it better to do it like above or should I pass the tool into the GunClass constructor and do it like below, where I only have to just create the gun object in the regular script and let the class do all the work
local GunClass = {}
GunClass.__index = GunClass
function GunClass.new(Tool)
local self = setmetatable({}, GunClass)
Tool.Equipped:Connect(function()
self:Equip()
end)
Tool.Unequipped:Connect(function()
self:Unequip()
end)
return self
end
function GunClass:Equip()
print("Equipped")
end
function GunClass:Unequip()
print("Unequipped")
end
return GunClass