Mob spawns but does not go

So, I have a script that spawns a mob, then he has to go to the right point, and when he reaches the end then dies and begins a new wave. In principle, this is the basic mechanics of any game of the genre “tower defense”. But as you can see the mob is spawned but does not go. Here are the screenshots and my code: As I understand the problem in the function “Move”

local mob = require(script.Mob)
local map = workspace.map

for wave = 1, 5 do
	print("WAVE STARTING:", wave)
	
	if wave < 5 then
		--print("1")
		mob.Spawn("Mob1", 3 * wave, map)
		--print("2")
	elseif wave == 5 then
		mob.Spawn("Zombie", 100, map)
	end
	
	repeat
		task.wait(1)
	until #map.Mobs:GetChildren() == 0
	print("WAVE ENDED")
	task.wait(1)
end 

This was a script to configure the spawn, and here is my main script that spawns a mob and is engaged in its movement.

local ServerStorage = game:GetService("ServerStorage")
local mob = {}

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

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

function mob.Spawn(name, quantity, map)
	local mobExists = ServerStorage.Mobs:FindFirstChild(name)
	
	if mobExists then
		for i = 1, quantity do
			task.wait(0.5)
			local newMob = mobExists:Clone()
			newMob.Parent = map.Mobs
			
			newMob:PivotTo(map.Path.Start.CFrame)
			

			coroutine.wrap(mob.Move)(newMob, map)
		end
		
	else
		warn("Requested mob does not exists:", name)
	end
end

return mob

And here are all the screenshots:

1 Like

Make sure the HumanoidRootPart of the mob is unanchored.

Check the properties of the mob and make sure that everything is unanchored

HumanoidRootPart, the mob is not anchored, here is a screenshot:

The code seems to work for me, perhaps try changing the mob model itself?

I checked everything, all the parts are unanchored, and also CanCollide = false

If you want, I can send you the model file, you can check it yourself, and in the meantime, you can understand exactly what the problem is.

Yeah sure, I don’t mind taking a look.

Okay, here’s the file.

Mob1.rbxm (17.6 KB)

Yeah, it is a model issue, the code works fine when you test it with a dummy instead.

Yes, I have a Zombie model that I took from the toolbox. And it works fine, it appears to go to the mark, is removed, and then starts a new wave. But here, when I just created a dummy, and gave him clothes model does not want to work

The issue seems to be that the PivotTo method is not moving the mob to the start of the path. Instead, you should set the position of the mob to the start of the path.

Here’s the updated code for the mob.Spawn function:

function mob.Spawn(name, quantity, map)
	local mobExists = ServerStorage.Mobs:FindFirstChild(name)
	
	if mobExists then
		for i = 1, quantity do
			task.wait(0.5)
			local newMob = mobExists:Clone()
			newMob.Parent = map.Mobs
			
			newMob:SetPrimaryPartCFrame(map.Path.Start.CFrame) -- set the position of the mob to the start of the path

			coroutine.wrap(mob.Move)(newMob, map)
		end
		
	else
		warn("Requested mob does not exists:", name)
	end
end

By setting the primary part CFrame of the mob to the start of the path, the mob will start moving towards the waypoints in the mob.Move function.

Appears here is the error, as I understand it is because I have a model of a mob, not Part.