Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to fix 'humanoid is not a valid member of noob' on line 24?

Asked by 1 year ago
Edited 1 year ago

The error is: humanoid is not a valid member of noob even though it is a valid member of noob Please help.

local tower = script.Parent
local mobs = workspace.Enemies

local maxDistance = 50
local nearestTarget = nil

local function FindNearestTarget()
    for i, target in ipairs(mobs:GetChildren()) do
        local distance = (target.HumanoidRootPart.Position - tower.Position).Magnitude
        print(target.Name, distance)
        if distance < maxDistance then
            print(target.Name .. "is the bal")
            nearestTarget = target
            maxDistance = distance
        end
    end

    return nearestTarget
end
while true do
    local target = FindNearestTarget()
    if target then
        target:WaitForChild("Humanoid"):TakeDamage(25)
    end
    task.wait(1)
end
0
And it is also infinite yielding. hex2decimal 2 — 1y

1 answer

Log in to vote
0
Answered by 1 year ago

To fix the “infinite yield possible” warning, you simply have to add the amount of seconds it should wait for a child. Ex. :WaitForChild("Humanoid") ? :WaitForChild("Humanoid", 30) to wait 30 seconds.

As for the “Humanoid is not a valid member of noob” error, your “Noob”-NPC simply doesn't contain a humanoid or at least one with the name of “Humanoid” it seems.

Ad

Answer this question