Why cant arguments be passed into this method from a module

Hello, I have ran into a very major issue within my game. When attempting to use the utility modules and their methods and when attempting to call them with certain arguments, the methods receive no data, and thus are given nil or self is the argument itself.

Here is an example
Example

--OOP AI
function Enemy:BindDamageTo(part, bindTime)
	local hitted = {}
	local damageBind = part.Touched:connect(function(hit)
		local char = hit.Parent
		local player = Players:FindFirstChild(char.Name)
		if not player then return end
		local ishumAlive = self:UseOutsideModule(HumanoidUtility, "IsHumanoidAlive", char) -- SOURCE OF ERROR
`--LINE ABOVE IS  THE SOURCE OF ERROR
		if not ishumAlive then return end
		if hitted[char] ~= nil then
			hitted[char] = char
			local damage = self:GenerateDamage()
			char.Humanoid:TakeDamage(damage)
			wait(bindTime / 5)
			hitted[char] = nil
		end
	end)
	wait(bindTime)
	damageBind:Disconnect()
	hitted = {}
end


--UTILITY Module code
function HumanoidUtility:IsHumanoidAlive(obj)
	local hum, humRoot, _, _ = self:GetMajorComponents(obj)
	if not hum or not humRoot then return false end
	if hum.Health < 1 then return false end
	return true
end

The following error occurs

19:48:47.055 - GetMajorComponents is not a valid member of Model
19:48:47.056 - Stack Begin
19:48:47.056 - Script ‘ServerScriptService.ServerUtility.HumanoidUtility’, Line 23 - function IsHumanoidAlive
19:48:47.057 - Script ‘ServerScriptService.EnemyObjects.Enemy’, Line 27 - function UseOutsideModule
19:48:47.057 - Script ‘ServerScriptService.EnemyObjects.Enemy’, Line 167
19:48:47.058 - Stack End

It seems to refer to self as the given argument for some reason

Is there any solution to my situation?

A major note:
The form of

function HumanoidUtility:IsHumanoidAlive(obj)

is equivalent to

HumanoidUtility.IsHumanoidAlive = function(self, obj)

Moreover, the utility modules do work; I have tested them. It is only in this given scinario
Not only is this the fact, but the arguments, before being used as in an attempt as a arugment, is NOT nil

Where do you define the function? The error is saying that this function does not exist, not anything about the line you pointed out with your comment.

2 Likes

it dose exist; I only had given a portion of the module

local R15_TORSO_NAME = "UpperTorso"
local R6_TORSO_NAME = "Torso"


local HumanoidUtility = {}

function HumanoidUtility:GetMajorComponents(obj)
	local hum  = obj:FindFirstChildOfClass("Humanoid")
	local humRoot = obj:FindFirstChild("HumanoidRootPart")
	local torso
	if hum ~= nil then
		if hum.RigType == Enum.HumanoidRigType.R15 then
			torso = obj:FindFirstChild(R15_TORSO_NAME)
		elseif hum.RigType == Enum.HumanoidRigType.R6 then
			torso = obj:FindFirstChild(R6_TORSO_NAME)
		end
	end
	local head = obj:FindFirstChild("Head")
	return hum, humRoot, torso, head
end

function HumanoidUtility:IsHumanoidAlive(obj)
	local hum, humRoot, _, _ = self:GetMajorComponents(obj)
	if not hum or not humRoot then return false end
	if hum.Health < 1 then return false end
	return true
end

return HumanoidUtility
1 Like

The issue also lies in the fact that the “self” is being refered to the argument, “obj.” Normally the “self” refers to the module, “HumanoidUtility”

1 Like

Well, your issue is probably somewhere in your UseOutsideModule function.

Is there any reason you can’t just do HumanoidUtility["IsHumanoidAlive"](HumanoidUtility, char) there instead?

2 Likes

Actually, the UseOutsideModule function was an attempt to solve the issue as I theorized it had to do something with a function being called by a function within a corutine thread which is stored in a Enemy object with a meta table attached to it

Without the UseOutsideModle, basically doing HumanoidUtility [ IsHumanoidAlive ] (char), it yields the same results

Make sure you’re passing HumanoidUtility as the first argument if you’re using bracket syntax instead of colon syntax.

2 Likes

however, to add onto your point, isHumAlive = HumanoidUtility:IsHumanoidAlive(char) still yeilds the same result
The same issue occurs with other working utility modules

Idk know, but the issue is fixed for some reason.