Attempt to call a nil value on server-side module script

I’m trying to use a module’s functions on a server script, however I get the error "attempt to call a nil value " on this specific line:
NPC_Utility.insertCharacter(character)

Server

local ServerScriptService = game:GetService("ServerScriptService")

-- module scripts
local NPC_Utility = require(ServerScriptService.NPC.StalkerScripts:WaitForChild("StalkerController"))

function UpdateCharacterList(character)
	NPC_Utility.InsertCharacter(character)
	print(NPC_Utility.GetCharacterTable())
end

Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function(character)
		UpdateCharacterList(character)
	end)
end)

Module

local utility = {
	CHARACTER_LIST = {},
}

function utility.InsertCharacter(character)
	table.insert(utility.CHARACTER_LIST, character)
end

function utility.RemoveCharacter(character)
	local index = table.find(utility.CHARACTER_LIST, character)
	table.remove(utility.CHARACTER_LIST, index)
end

function utility.GetCharacterTable()
	return utility.CHARACTER_LIST
end

return utility

print these and tell me what they return:

print("NPC_Utility type:", type(NPC_Utility))
print("InsertCharacter type:", type(NPC_Utility.InsertCharacter))
print("Module contents:", NPC_Utility)

Oh crap I had a feeling I forgot to mention something in my OP
I’ve already tried printing out NPC_Utility and it’s not nil, the problem seems to be with the functions. All of them are nil for some reason.

Okay, Where is your module located?

1 Like

Thanks, I was referencing the wrong location.
My modulescript was at ServerScriptService.NPC not ServerScriptService.NPC.StalkerScripts

1 Like

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