A problem with a ModuleScript

Hey! im making a simple tower defense game and i got a module script.
but the problem is that everytime i run this script


local ServerStorage = game:GetService("ServerStorage")
local MOB = {}
function MOB.Move(mob, map)
	local humanoid = MOB:WaitForChild("Humanoid")
	local waypoints = workspace.WayPoints

	for waypoint=1, #waypoints:GetChildren() do
		MOB.Humanoid:MoveTo(waypoints[waypoint].Position)
		MOB.Humanoid.MoveToFinished:Wait()
	end
end
function MOB.Spawn(name, map)
	local mobExists = ServerStorage.MOBS:FindFirstChild(name)
	
	if mobExists then
		local newMob = mobExists:Clone()
		newMob.HumanoidRootPart.CFrame = map.ZombieSpawn.CFrame
		newMob.Parent = workspace
		
		MOB.Move(newMob, map)
	else
		warn("idk")
	end
end

return MOB

i get this error:
ServerScriptService.Main.MainModuleScript:4: attempt to call missing method ‘WaitForChild’ of table

1 Like

The issue is this line

MOB:WaitForChild("Humanoid")

I believe you meant for it to be

mob:WaitForChild("Humanoid")

Alright ill try that real quick.

1 Like

Alright so forgot to include one more thingy.
under the

if mobExists then
		local newMob = mobExists:Clone()
		newMob.HumanoidRootPart.CFrame = map.ZombieSpawn.CFrame
		newMob.Parent = workspace

theres this line

MOB.Move(newMob, map)

and then i get this error

ServerScriptService.Main.MainModuleScript:8: attempt to index nil with ‘MoveTo’

Same issue as before.
Replace

function MOB.Move(mob, map)
	local humanoid = MOB:WaitForChild("Humanoid")
	local waypoints = workspace.WayPoints

	for waypoint=1, #waypoints:GetChildren() do
		MOB.Humanoid:MoveTo(waypoints[waypoint].Position)
		MOB.Humanoid.MoveToFinished:Wait()
	end
end

with

function MOB.Move(mob, map)
	local humanoid = mob:WaitForChild("Humanoid")
	local waypoints = workspace.WayPoints

	for waypoint=1, #waypoints:GetChildren() do
		mob.Humanoid:MoveTo(waypoints[waypoint].Position)
		mob.Humanoid.MoveToFinished:Wait()
	end
end

I stopped getting the error and everything works now. thank you!

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