Humanoid is not a valid member of Model "Zombie"

The tower wont attack the other enemy instead when it kills 1 enemy an error will pop up - Humanoid is not a valid member of Model "Zombie"

	local function Splash(targeted, obj)
		targeted.Humanoid:TakeDamage(obj.Config:WaitForChild("Damage").Value)
		local radius = obj.Config.SplashRadius.Value
		local Ymargin = 3 -- this is how high or below your target can be from the splash. Make it higher to make it more lenient.
		local Enemies = workspace.Mobs:GetChildren()
		local targets = {}
		for i, target in pairs(Enemies) do
			local vectordistance = (targeted:WaitForChild("HumanoidRootPart").Position - target:WaitForChild("HumanoidRootPart").Position) -- this is a vector
			local distance = vectordistance.Magnitude -- this is a number
			local Ydistance = math.abs(vectordistance.Y) -- number that displays how far they are from each other on the Y-axis

			if distance <= radius and Ydistance < Ymargin and target ~= targeted then
				table.insert(targets, target)
				targeted.Humanoid:TakeDamage(obj.Config:WaitForChild("Damage").Value)
			end
		end
	end

Please Help me on fixing this issue

I just modified your for loop:

for i, target in pairs(Enemies) do
        local targetHumanoidRootPart = target:FindFirstChild("HumanoidRootPart")
        local targetHumanoid = target:FindFirstChild("Humanoid")
        
        if targetHumanoidRootPart and targetHumanoid then
            local vectordistance = (targeted.HumanoidRootPart.Position - targetHumanoidRootPart.Position) -- this is a vector
            local distance = vectordistance.Magnitude -- this is a number
            local Ydistance = math.abs(vectordistance.Y) -- number that displays how far they are from each other on the Y-axis

            if distance <= radius and Ydistance < Ymargin and target ~= targeted then
                table.insert(targets, target)
                targetHumanoid:TakeDamage(obj.Config:WaitForChild("Damage").Value)
            end
        end
end

It will check if humanoid rootpart and humanoid exists and then access it.
Let me know if it helps.

i forgot to mention that the error is over here

Then add this

local targetedHumanoid = targeted:FindFirstChild("Humanoid")
if targetedHumanoid then
    targetedHumanoid:TakeDamage(obj.Config:WaitForChild("Damage").Value)
else
    warn("No Humanoid found in targeted model:", targeted.Name)
end

Right below the function

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