Modulescript functions reading arguments as nil

Hello, i;ve been stuck on this problem for a few days now and i still don’t understand why.
So basically, i have a modulescript that handle’s quests in my game;

The main dilemma is that i’ve used the first function in a normal script and it prints the Id and Name perfectly, but if i do the same but with a function inside the same modulescript, it reads all arguments as nil(Even though they exist for the entire period of me calling the functions)

The problem functions are here

function module:GetTask(Id: any, Name:string)
	print(Id,Name)
	--assert(Id ~= nil and Name ~= nil, "Id or Name are nil")
	local Tasks = CurrentTasks[Id]
	if Tasks == nil then warn("No task list found for id", Id) return end
	local Target

	for i, tbl in pairs(Tasks) do
		if typeof(tbl) == "table" then 
			if tbl.Name == Name then
				if tbl ~= nil then
					return tbl
				end	
			end
		end	
	end
end

function module:InputToTask(TaskTable, Path: string, Value: any)	
	print(TaskTable.Id, TaskTable.Name)-- Always prints 1234, "Cool"
	local Task = self:GetTask(TaskTable.Id, TaskTable.Name) -- When used here, the function reads nil,nil and returns nil
	
	if TaskTable and CurrentTasks[TaskTable.Id] and Task and Task[Path] then
		Task[Path].Progress = Value
		TaskExpansive.TaskChanged:Fire(Task.Id, Task[Path].Progress)
		GetTaskCompletionStatus(Task[Path], Task.Id)
		GetTaskListCompletionStatus(Task.Id)
	else
		warn("No path exists for "..Path)
	end
end

Normal script calling these functions

local theTask = taskmod:GetTask(1234,"Cool") -- functions properly
print(theTask) -- prints the table perfectly

task.wait(5)
taskmod:InputToTask(theTask,"Quest1",true)

Any help would be appreciated

1 Like

Is module indexed to itself?
So…

module.__index = module

hopefully my syntax is right
Also have you printed self?

yes, i have put that line just under the

module = {}

Do you expect this line to return something?

It returns a table that contains the Id,name, individual objectives of each quest assigned to a player

Wait then what is the exact issue here? You claimed that the line quoted returns nil in your comments. I assumed that was the issue.

The problem is that when calling the module:InputToTask function which changes a value from the task, i’m passing in the id and the name of the task i want to get, it print’s out the id and name correctly within :InputToTask() which then calls :GetTask(), passing in the same id and name that exists but :GetTask() reads nil,nil in the arguments

I believe the issue lies

Have you tried to print Tasks?
Your condition statements would lead me to believe that this would be the only cause?
EDIT:
If it print’s nil then you might want to change

to:

local Tasks = CurrentTasks[tonumber(Id)]

What is taskmod? Is it an object created by the module or the module itself?

taskmod is a table returned by the module that contains the Task (with specifications of the Id the task belongs too/Name/etc)the player(in this case a test) has. Currently this system does not utilize OOP because i’m not sure about the performance difference between event based functions and OOP

The Id is a number by default, and when i print Tasks when called from the normal script it prints the table correctly, but when i call the function from within :InputToTask(), it reads the arguments as nil. I might just consider copying it and making it a local function within InputToTask()

Consider changing this line to…

local Task = module:GetTask(TaskTable.Id, TaskTable.Name)

There seems to be some issue with how the module is being constructed. Where the table isn’t binding with the function, so calling self just doesn’t work. The module in this case will work.

It still results in reading the arguments as nil

Are you sure this is a table returned by the module that inherited the module’s functions and isn’t just the module itself?
image

No wait sorry i got confused, taskmod IS the module, while theTask is the table returned by the module

Ok, so i actually just stumbled across a solution a few minutes ago, what i did was i checked the other arguments in functions across the modulescript and found one that was missing an argument and causing an error which lead up to a cascade of problem’s inside the modulescript. Once i added the necessary argument in that function call the function reading nil arguments sort of just fixed itself. Thank you again everyone who commented and helped