Npc goes only to 4 waypoints and then skips to the end

hello, i was making a tds game until i noticed while i was making new maps. the zombie ai only moved to 4 paths and then skipped to end, this npc does not use humanoid but i dont know whats the issue because with old version of zombie (humanoid) also has that issue.
how could i fix this

this is the waypoint script (not going to show the rest)

task.defer(function()
local waypoints = bruh.Waypoints:GetChildren()
for i,v in ipairs(waypoints) do
	repeat
		task.wait()
		local vpos = v.Position+Vector3.new(0,2.93,0)
	        script.Parent.HumanoidRootPart.AlignOrientation.CFrame = CFrame.lookAt(script.Parent.HumanoidRootPart.Position,vpos)
			script.Parent.HumanoidRootPart.AlignPosition.Position = vpos
		until (v.Position-script.Parent.HumanoidRootPart.Position).Magnitude < 3
		--until task.wait((v.Position-script.Parent.HumanoidRootPart.Position).Magnitude / script.Parent.HumanoidRootPart.AlignPosition.MaxVelocity)
		if v.Name == "End" then
			workspace.BaseHP.Value -= npc.Health.Value
			npc:Destroy()
		end
end
end)

edit: theres 16 waypoints, and they all follow the path.

1 Like

anyone? hello.

132193219932193312993122913

1 Like

Let me reformat your code so I can understand this better:

local npcHeight = 2.93
task.defer(function()
	local waypoints = bruh.Waypoints:GetChildren()
	for _,waypoint in ipairs(waypoints) do
		local targetPos = waypoint.Position+(Vector3.yAxis*npcHeight)
		script.Parent.HumanoidRootPart.AlignOrientation.CFrame = CFrame.lookAt(script.Parent.HumanoidRootPart.Position,targetPos)
		script.Parent.HumanoidRootPart.AlignPosition.Position = targetPos
		
		repeat task.wait(.2) until (waypoint.Position-script.Parent.HumanoidRootPart.Position).Magnitude < 3
		--until task.wait((waypoint.Position-script.Parent.HumanoidRootPart.Position).Magnitude / script.Parent.HumanoidRootPart.AlignPosition.MaxVelocity)
		if waypoint.Name == "End" then
			workspace.BaseHP.Value -= npc.Health.Value
			npc:Destroy()
		end
	end
end)

Can you show the folder containing all the waypoints? Does the script also wait for the waypoints to load before continuing?

  1. theres nothing special in the waypoints folder, its just 1x1 invisible parts that are inside the floor which names go in order.
  2. in the very very start of the script it waits until it finds the map and waypoints.

Sometimes PathFinding Service Can Time out I suggest adding more waypoints so that it doesn’t time out

sorry but im using MoveTo map waypoints not pathfinding service.

Ok, I still suggest adding more waypoints and see if that works.

em
em

it might be because the waypoint its skipping start (3) might be too close and its magnitude is less than 3.

edit: the code didnt change anything… ill edit the thing that might break the code (3th waypoint)
edit 2: even after editting the waypoints it still breaks, on older maps they work better and dont bug out

nothing changed, the npcs have a little delay now

Oh sorry just checking did you add them between they waypoints that are spaced out?

yeah, i also added a debug zombie but it still breaks…
aaa
a
aa
a
a
a
a

what type of script is the script that controls the zombie’s movement?

ServerScript, its in the npc itself

I had An Old TD game but I gave up on it due to being burnt out the enemy’s movement was controlled by the server and I never had an issue occur so I suggest doing that. I’m not the best scripter but I’m going to suggest using PathFindingService as it is the best thing to use in this scenario. I’m going to try and go back into my Old TD game and see if there’s anything I can use from that old game and see if there is anything that I can share that can help you.

i had a pathfinder for test and it did not change anything too.

Ok This is the script that I used To Move My Mobs Turns out it actually used MoveTo also

local map= game.Workspace["Foggy Shores"] -- Set this to your map

local humanoid = script.Parent.Humanoid
local waypoints = map.Waypoints -- Your Waypoints -- Set This to what your waypoints are
script.Parent.HumanoidRootPart.CFrame = map.Start.CFrame
for waypoint=1, #waypoints:GetChildren() do -- Gets all the children Of The Waypoints Folder
	humanoid:MoveTo(waypoints[waypoint].Position) -- Moves The Enemy To The Waypoints
	humanoid.MoveToFinished:Wait()
end

script.Parent:Destroy() -- Destroys The Zombie Once It reaches The End

I Hope This Helps This is A New MoveTo() script If an error occurs Let me Know Please

This Is A server Script btw and should be in your enemy.

isnt thats the same code from mine but it uses humanoid:MoveTo()?
i mean that couldn’t help.

also im using a fake rig no humanoid, old humanoid rig with MoveToFinished actually skipped the first waypoint.

Sorry I can’t help you there because I Have no experience with MoveTo()
with a model without a humanoid also I wrote This code back in December 2021 with the help of a Youtuber/Developer Gnome Code his TD tutorial is on his channel

You can also add a wait to check if the zombie has reached a waypoint.