Module function calling as nil (sorry for posting twice)

So im making a commands list however ive come across a issue, when i call a function from a module script its calling as nil?
Error location:

Commands.KillAll()

This is the varaible for “Commands”

local Commands = require(script.Modules.Commands)

And heres where the function is located inside of the module script.

function KillAll()
	for i,v in pairs(game.Players:GetPlayers()) do
		v.Character.Humanoid.Health = 0
	end
end

This is because your KillAll() function is not added to the table returned by the module.

I’m assuming your module script looks something like this:

local Commands = {}

function KillAll()
	for i,v in pairs(game.Players:GetPlayers()) do
		v.Character.Humanoid.Health = 0
	end
end

return Commands

If so, a simple fix, just change your function definition so that it is added to the table returned by the module:

function Commands.KillAll()
2 Likes

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