Attempt to call missing method 'WaitForChild' of string

I am not sure why I am getting this error on line 41. How can I rectify the issue that the output is displaying? I have attached a screenshot below.

Thanks to anyone who is able to provide me some help.

--[[SERVICES]]--
local serverStorage = game:GetService("ServerStorage")
local physicsService = game:GetService("PhysicsService")

--[[VARIABLES]]--
local spawnInterval = 0.5

local enemy = {}

function enemy.moveEnemy(npc, floor, tycoon)
	local humanoid = npc:WaitForChild("Humanoid")
	local towerDefencePaths = tycoon:WaitForChild("TowerDefencePaths")
	local points = floor:WaitForChild("Points")

	for point = 1, #points:GetChildren() do
		humanoid:MoveTo(points[point].Position)
		humanoid.MoveToFinished:Wait()
	end
	npc:Destroy()
end

function enemy.spawnEnemy(name, amount, floor, tycoon)
	print(name, amount, floor, tycoon)
	local enemyCheck = serverStorage:WaitForChild("TowerDefenceNPCs"):FindFirstChild(name)
	local pathFolder = tycoon:WaitForChild("TowerDefencePaths")
	
	if enemyCheck then
		print("enemy check completed", enemyCheck, enemyCheck.Parent)
		for i =1 , amount do
			task.wait(spawnInterval)
			local enemyClone = enemyCheck:Clone()
			enemyClone:WaitForChild("HumanoidRootPart").CFrame = tycoon:FindFirstChild(floor).Points:FindFirstChild("Spawn").CFrame
			enemyClone.Parent = tycoon:WaitForChild("NPCs"):FindFirstChild(floor)
			enemyClone:WaitForChild("HumanoidRootPart"):SetNetworkOwner(nil)
			
			enemyClone.Humanoid.Died:Connect(function()
				task.wait(0.5)
				enemyClone:Destroy()
			end)
			print(enemy.moveEnemy, enemyClone, floor, tycoon)
			coroutine.wrap(enemy.moveEnemy)(enemyClone, floor, tycoon)
		end
	else
		warn("Enemy: ".. enemy.. " was not found.")
	end
end

return enemy

That’s because WaitForChild is not a method that’s available for strings. It’s for instances only. With that being said, there’s nothing that jumps out at me as being wrong with your script. You may want to check what’s calling those functions and make sure you are passing the correct type and number of parameters.

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