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

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

Asked by 1 year ago
Edited 1 year ago

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

Log in to vote
0
Answered by 1 year ago

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).

Ad

Answer this question