Wait For child not working

  1. What do you want to achieve? Keep it simple and clear!
    I want to fix this this Error/Warning : Infinite yield possible on ‘Noob:WaitForChild(“Humanoid”)’
  2. What is the issue? Include screenshots / videos if possible!
    error
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tried several methods some say try to loop, FindFirstChild, reset the code nothing worked.
    After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

function Mob.Move(mob, map)

local waypoints = map.waypoints
for waypoint=1, #waypoints:GetChildren() do
	    local Humanoid = mob:WaitForChild("Humanoid")
	    Humanoid:MoveTo(waypoints[waypoint].Position)
	    Humanoid.MoveToFinished:Wait()
	    Humanoid:MoveTo(waypoints[waypoint].Position)
	    Humanoid.MoveToFinished:Wait()
end     
ServerStorage.Bindables.DamageBase:Fire(mob.Humanoid.Health/2)
mob:Destroy()   

end

You may know already this is the code from gnome code td series. The error is saying that humanoid is not a valid member of mob in simple terms but the name is same and the mob does have humanoid its been days looking for solution please help. I’m at the peak of my desperation.

2 Likes

Try this:

local Humanoid = mob:WaitForChild("Humanoid", 12) --// The 12 is how many seconds it will wait for it

Note: if this still doesn’t work then it’s probably because mob doesn’t have a Humanoid

1 Like

First of all ty for fast replay,

I tried your solution but now its giving me this error
ServerScriptService.Main.Mob:10: attempt to index nil with ‘MoveTo’

the mob do have Humanoid and the spelling is also correct

1 Like

Try swapping it to:

local Humanoid = mob:FindFirstChildOfClass("Humanoid")

You could aslo try adding a this above it:

print(mob.Name) --// Make sure it prints out "Noob"

Capture

heres the Humanoid picture so its easy to understand the error

Where did you insert script and character into?

Capture2
Capture3
for just testing i was only running the code on the noob mob

the main script is in ServerScriptService and the Mobs Folder is in ServerStorage

You could directly check from Gnome Codes game file if you’re doing it right:
https://gnome.codes/tutorials/TowerDefense/

Quick question, is the mob getting cloned into Workspace before u use :MoveTo()?

i was following him i was at ep 8 or 9 smth but then i took a short break for about 7-9 days and when i came back this error appeared and ruined everything sadly

nope its not cloned to workspace strangely idk why

local PhysicsService = game:GetService(“PhysicsService”)
local ServerStorage = game:GetService(“ServerStorage”)
local Mob = {}

function Mob.Move(mob, map)

local waypoints = map.waypoints
for waypoint=1, #waypoints:GetChildren() do
	    print(mob.Name)
	    local Humanoid = mob:FindFirstChildOfClass("Humanoid",12)
	    Humanoid:MoveTo(waypoints[waypoint].Position)
	    Humanoid.MoveToFinished:Wait()
	    Humanoid:MoveTo(waypoints[waypoint].Position)
	    Humanoid.MoveToFinished:Wait()
end     
ServerStorage.Bindables.DamageBase:Fire(mob.Humanoid.Health/2)
mob:Destroy()   

end

function Mob.Spawn(name, quantity, map)
local mobExists = ServerStorage.Mobs:WaitForChild(name)

if mobExists then
	for i=1, quantity do
		task.wait(0.5)
		local newMob = mobExists:Clone()
		newMob.HumanoidRootPart.CFrame = map.Part.CFrame
		newMob.Parent = workspace.Mobs
		newMob.HumanoidRootPart: SetNetworkOwner (nil)
		for i,object in ipairs(newMob:GetDescendants())do
				if object:IsA("BasePart")then
					object.CollisionGroup = "Mob"
				end
		     end
	        newMob:WaitForChild("Humanoid").Died:Connect(function()
			newMob.Parent = workspace
			wait (3)
			newMob:Destroy()
		end) 
		if newMob.Humanoid.Health >= 0 then
			newMob:Destroy()
		end
coroutine.wrap(Mob.Move)(newMob, map)
	end
else
	warn("Mob not found:", name)
end

end

return Mob

heres the full code for better understanding

Can you give us game test video?

robloxapp-20240704-1711140.wmv (1.2 MB)

idk how to record better than that sorry

what output says error now? ㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤㅤ

ServerScriptService.Main.Mob:44: ServerScriptService.Main.Mob:11: attempt to index nil with ‘MoveTo’

local mobExists = ServerStorage.Mobs:WaitForChild(name)

Does this part come out correctly when printed?

yes it i tried print mob.name and it printed Noob