Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why am I getting the error: attempt to index function with 'WaitForChild'?

I really don't know how to fix this, I know the line it is on but no matter what I try it doesn't work! Here is a snippet of the "bad code" by the way all the rest of the code works and I also returned the module. This is a modulescript.

local mob = {}
local ServerStorage = game:GetService("ServerStorage")
local Mobs = ServerStorage.Mobs
local space = game:GetService("Workspace")
local map = space.Map

function mob.Move(mob, map)
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = map.Waypoints
	for waypoint=1, #waypoints:GetChildren() do
		humanoid:MoveTo(waypoints[waypoint].Position)
		humanoid.MoveToFinished:Wait()
	end
end

1 answer

It turns out it was actually some other code in a different line it was: coroutine.wrap(mob.Move)(mob.Move) and the 2nd parameter of coroutine.wrap was meant to be (newMob, map).

This discussion is preserved as it was. New answers, comments, and votes are closed.