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