Need help for my Enemy Movement on my TD Games

Hello, i want to make a new tower defense game without a kit. but I found this problem…

Any ideas on how to fix it?.
this is the scripts.

function enemy.Move(Enemy)
	local Humanoid = Enemy:WaitForChild("Humanoid")
	
	local path = Pathfindingservice:CreatePath()
	
	for i = 1, #MapPath:GetChildren() do
		if i == #MapPath:GetChildren() then
			Enemy:Destroy()
			Map:WaitForChild("EnemyCount").Value -= 1
			break
		end
		local Finished = false
		Humanoid:MoveTo(MapPath[i + 1].Node.WorldPosition)
		print(Enemy.Name, "is moving to ", i + 1)
		Humanoid.MoveToFinished:Wait()
		print(Enemy.Name, "Move finished.")
	end
end

Thanks~

It looks like only the noobs with golden heads are moving like that. Are you sure all enemies are using the same function?

Its because of pathfinding service. Since it’s trying to get the fastest path. I’d recommend you make a folder and add waypoints so at the end of each corner, add a part and name it 1-2-3 etc. Then type this into a script:

for i,v in pairs(folderhere) do
	humanoid:MoveTo(v.Position)
	humanoid.MoveToFinished:Wait()
end

Pathfinding service isn’t used here. The path is created but never used.

i did make waypoints each corner of the path. but somehow that happen

Yes, all the enemies using the same function

If :MoveTo() takes too long it will automatically be set to finished, because the game thinks the npc is stuck. The noobs with the golden heads move slowly and it might be why they’re skipping some nodes.

Owhh…i see. how do i fix it? any solutions?

You can try tweening the characters instead and getting the walk time by having the distance divided by the walk speed.

You could also repeat MoveTo() until the distance between the character and the node is less then 4 studs or smaller. Humanoid:MoveTo (roblox.com) also has a solution on how to remove the timeout.

1 Like

Alright, thanks for helping me. it’s working now^^

Just got another issue, where the enemy stuck not moving at all.?

Did you add a function to the andThen parameter of moveTo()?

Why dont u use tweenservice for td path. its the best way to do the enemy movements. im currently working on a td game too and mine works perfectly with the tweens

hmm, then how to slow the enemy down when tween still running?

Im not doing that at all i just do stuns but i think slowing down could be possible

The only issue with tween service is that it is performance heavy when used on the server

i dont see any lag even though i spawn a lot of them

Look at your performance stats

If you are going to tween on the server, I suggest using [UPDATED 12/7/20] Advanced Server to Client Tweening Module For Beginners
or
TweenService V2

1 Like