Cannot understand the error

I cant see why it errors cannot call non-function nil

--using the function
local player_handler = require(script.Parent.Parent.PlayerRelated.PlayerHandler)
--other stuff here
for _, player: Player in player_handler.PlayersNotInGame do
		player_handler:SwitchPlayerArray(player: Player) -- cannot call non-function nil error here
                 --other stuff here
--defining in module
function player_handler:SwitchPlayerArray(player: Player): ()
	--If the player is InGame, then move him into NotInGame
	if table.find(self.PlayersInGame, player) then
		return table.insert(self.PlayersNotInGame, table.remove(self.PlayersInGame, table.find(self.PlayersInGame, player)) :: Player)
	end 
         --other stuff here

Thank you

1 Like

Isn’t the original Module function called using ‘Module.FunctionName()’ method?

1 Like

I suspect that where you require the module function it may be an incorrect reference. I think the script.parent.parent etc. may be wrong. That or like the guy above me said, maybe the syntax is wrong with the missing ‘()’.

1 Like

I don’t think you can do type-checking in your arguments,

player_handler:SwitchPlayerArray(player) -- no ": Player"
2 Likes

Also not sure if you can require just a function instead of requiring the module and then saying “module.func()”.

1 Like

The error is still there
That was the first thing I tried when I saw the error

1 Like

wdym by “require just a function”

I required the entire module when I use some functions from the module

I define the method using a colon instead of a period, because I need to automatically pass self (as you can see, I used self to access the other elements on the player_handler module)

To debug, try printing out player_handler after you require it.

Is it an empty table or a table without the member SwitchPlayerArray?

Apparently, it required a semi-colon, because the statement underneath looked ambiguous

Ambiguous syntax: this looks like an argument list for a function call, but could also be a start of new statement; use ';' to separate statements

1 Like

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