Why does "test" not print?

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! :slight_smile:

1 Like

I’m not sure what you mean. I tested the test module and the string was printed.

1 Like

It will indeed print on its own, but not with the main module up and running.

Is this where you required the test module?
Have you confirmed you required the correct module? A simple print outside should confirm it.

1 Like

Like this?

local compModule = require(componentScript)
	print(compModule)
	local newComp = compModule.new(self, instance)
	newComp:Init()

Inside the required module script;

print("required!")
local Test = {}
Test.__index = Test
1 Like

Still nothing. I kept getting the unable to load module error, but I think I fixed that with a simple WaitForChild() command.

I fixed it! I’m not really sure what was causing the problem, but I think it was this part of my server script:

local Tycoon = require(script.Parent.Tycoon)

game:GetService("Players").PlayerAdded:Connect(function(Player)
	local tycoon = Tycoon.new(Player)
	Tycoon:Init()
end)

I was calling the :Init() method of the Tycoon module, not the created tycoon from the line above. Thank you for your replies and have a wonderful day! :slight_smile:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.