Zombie is skipping waypoint after a bit

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Im TRYING to make a tower defense game

  2. What is the issue? Include screenshots / videos if possible!
    The zombie moves fine, but a bit after it reaches the first waypoint (after the start waypoint) it skips the second waypoint and moves to the third waypoint (end waypoint as the map is temporary and simple)








    (i had to use a bunch of screenshots because video record wasnt working in Run for some reason)

  3. What solutions have you tried so far? Did you look for solutions on the Creator Hub?
    I added another waypoint in between 1st and 2nd, it worked, but i dont want to do this as i might make big maps and need a lot of them.

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

local map = game.Workspace:WaitForChild("Map")

local waypointsFolder = map:WaitForChild("Waypoints")
local amountOfWaypoints = 2
local startPoint = waypointsFolder:WaitForChild("Start")
local endPoint = waypointsFolder:WaitForChild("End")

local zombie = script.Parent
local humanoid = zombie:WaitForChild("Humanoid")

local animator = humanoid:WaitForChild("Animator")
local animation = script:WaitForChild("WalkAnimation")

-- Move to start point and play animation
local animTrack = animator:LoadAnimation(animation)
animTrack:Play()
humanoid:MoveTo(startPoint.Position)
humanoid.MoveToFinished:Wait()

-- Move through waypoints
for i = 1, amountOfWaypoints do
	local waypoint = waypointsFolder:WaitForChild(i)
	humanoid:MoveTo(waypoint.Position)
	humanoid.MoveToFinished:Wait()
end

-- Move to end point
humanoid:MoveTo(endPoint.Position)

Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.

1 Like

Not sure exactly what issue might be is, but WaitForChild require string not number as first argument, try to replace i in it with tostring(i). Also try printing waypoints to console or debug code to make sure they are coming in right order.

It prints the waypoint when it starts going to it and when it reaches it, but it also prints the waypoint (2) when it just decides to go to the next waypoint and skips waypoint 2

1 Like

So they are printing right but humanoid doesnt? Actually how far away your waypoints or how fast your humanoid, since there actually a timeout in :MoveTo about 8s, which is made for humanoids to not get stuck with .MoveToFinished:Wait(). Humanoid | Documentation - Roblox Creator Hub

Ah yeah it does skip after 8 seconds, is there any way to make it still move even though it ran out of time?

1 Like

As far as i know documentation’s code example for :MoveTo has that, to make a long story short you need to call :MoveTo more to reset timer, but do not overuse it like every heartbeat. Another solution could be some more waypoints as you mentioned before, but it is not always perfect solution since humanoids in your game could have different walk speeds.

2 Likes

I just copied the code from the documentation because im not the best scripter and i didnt know how to do it, but it works now! Im gonna mark your post as the solution because you told me where it is and how to do it

1 Like

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