Hello! I am currently trying to make a tycoon game using Object-Oriented Programming or (OOP) and everything seems to work for me so far, expect for something not printing.
Test module:
local Test = {}
Test.__index = Test
function Test.new(tycoon, instance)
local self = setmetatable({}, Test)
self.Tycoon = tycoon
self.Instance = instance
return self
end
function Test:Init()
print("Test was initialized") -- This doesn't print
end
return Test
Main Module Script:
local CollectionService = game:GetService("CollectionService")
local template = game:GetService("ServerStorage").Template
local ComponentsFolder = script.Parent.Components
local function NewModel(model, cframe)
local newModel = model:Clone()
newModel:SetPrimaryPartCFrame(cframe)
newModel.Parent = workspace
return newModel
end
local Tycoon = {}
Tycoon.__index = Tycoon
function Tycoon.new(Player)
local self = setmetatable({}, Tycoon)
self.Owner = Player
return self
end
function Tycoon:Init()
self.Model = NewModel(template, CFrame.new(0, 1, 0))
self:AddComponents(self.Model.Part)
end
function Tycoon:AddComponents(instance)
for _, tag in ipairs(CollectionService:GetTags(instance)) do
local component = ComponentsFolder:FindFirstChild(tag)
if component then
self:CreateComponent(instance, component)
end
end
end
function Tycoon:CreateComponent(instance, componentScript)
local compModule = require(componentScript)
local newComp = compModule.new(self, instance)
newComp:Init()
end
function Tycoon:Destroy()
self.Model:Destroy()
end
return Tycoon
Main server script:
local Tycoon = require(script.Parent.Tycoon)
game:GetService("Players").PlayerAdded:Connect(function(Player)
local tycoon = Tycoon.new(Player)
Tycoon:Init()
end)
It’s not really that important I figure this one out, but I would just like to know why it doesn’t print. If you need me to elaborate on anything or you think you know what’s causing the bug, please let me know. Thank you and have a wonderful day!