Pathfinding zombie

I’m trying to make a zombie AI and I came across a problem where sometimes the waypoints table is empty. Although the problem occurs only when using runService.Stepped (I suppose the stepped function runs multiple times and the script doesn’t have the proper time to load the waypoints). It works just fine when using while wait(.1) loop. Is there a problem using while wait() loop or should I make the script work with the Stepped function?

2 Likes

Maybe it just couldn’t find a path?

My guess is that if its running in stepped, it could give it a bigger chance of just not finding a path.

In the GetWaypoints documentation

I believe with this block of code I prevent this from happening

repeat
			triesReturning += 1
			success, errormessage = pcall(path.ComputeAsync, path, humRp.Position, startingPoint)
			if not success then
				warn("Path compute error: ".. errormessage)
				task.wait(retryCooldown)
			end
		until success == true or triesReturning > maxRetries

It probably returns an empty table rather than erroring.

Maybe your code should do something else if it is just empty.

Async calls can take longer time to return a result, so if you are seeing the empty waypoints in a stepped event, maybe the previous stepped event is still running.

Good luck with the zombie script. I have one of those, too. I have to admit that I am not happy with mine. Yet. :crazy_face:

Oh It does make sense. I will try using the disconnect function and we will see. If I make it work I will inform you

That might make the code a little difficult to work with. Or maybe it it just a personal preference I have, for this type of event I prefer to connect it once and for all.

You could also have a state variable that you change between different values to track what the zombie script is doing. If it is calculating, you could return from the stepped event.

You could combine it with a timestamp to make sure the script recovers if the async call fails. But if you use pcall as is usual for async it might not be necessary to have a timeout.

Yeah I agree that is working with disconnect is difficult for me. Like you I’m used to connect once and for all but the disconnect may make the script work. It will take some time though…

I found a solution and It works very well for my needs. So I used the waypoints until the zombie actually sees the players using ray. If the ray hits a player I added repeat until loop which make the zombie hunts the player . This video → https://www.youtube.com/watch?v=ibvoqnG3YqI&t=1535s&ab_channel=Y3llowMustang really helped

-- Above this script I used the waypoints and the pathfinding service
if rayhitsplayer then -- rayhitplayer is function which returns true if the ray detects a player else it returns false
   repeat
      human:MoveTo()
      if not target then
            break
      elseif target.Parent then
            break
      end
    until rayhitplayer == false or hum.Health < 1
end

Thanks for the replies :slight_smile:

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