How can I prevent zombies in my tower defense game from stopping for half a second at each point they go to?

  1. What do you want to achieve? I want to fix a bug in my tower defense game involving the enemies.

  2. What is the issue?
    I made it so the humanoid moves to a certain point so the enemies can move along the path. The problem is that they stop at each point for half a second before moving again and it looks like they’re stuttering.
    (The reason there are so many is because using MoveTo has a max of 8 seconds and my slow boss freezes if it doesn’t walk to another point.

  3. What solutions have you tried so far? I’ve tried reviewing the scripts to see if there are any wait times that are too long causing them to stutter, which didn’t work.

local hum = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")

local nodes = game.Workspace.Path1:GetChildren()
table.sort(nodes, function(nodeA, nodeB)
	local nodeNumberA = string.match(nodeA.Name, "%d+")
	local nodeNumberB = string.match(nodeB.Name, "%d+")
	return tonumber(nodeNumberA) < tonumber(nodeNumberB)
end)

for _, node in ipairs(nodes) do
	hum:MoveTo(node.Position)
	local distance = (torso.Position - node.Position).Magnitude
	wait (distance / hum.WalkSpeed)
end
1 Like


Video

Switch the goal a frame or so before they reach the goal. You might be able to use this control module which has a tested termination condition. I am also working on a more advanced pathfinder which will be building onto this controller, you can follow the progress or send feature requests here: Polaris-Nav

Honestly just replace this with

hum.MoveToFinished:Wait()

Unfortunately that method even fails to return sometimes… It is a very common issue developers have with the pathfinder, and why many alternatives have been made.

Where? It has never failed for me.

Here is one of the latest I have seen, and I have personal experience with it not working: Humanoid.MoveToFinished:Wait() Doesn't Fire Properly

2 Likes

try changing the network owner of the zombies to nil if you haven’t

How would I do that? I can try to see if it makes a difference.

loop through all the zombies and do SetNetworkOwner(nil) something like this:

for index, part in pairs(zombiesFolder:GetDescendants()) do
    if part:IsA("BasePart") then
        part:SetNetworkOwner(nil)
    end
end

Instead of making a custom wait function. Just use Humanoid.MoveToFinished:Wait()

Try this now this will work better

local hum = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")

local nodes = game.Workspace.Path1:GetChildren()

local targetReached = false
local function moveTo(targetPoint)
	targetReached = false
	local connection
	connection = hum.MoveToFinished:Connect(function(reached)
		targetReached = true
		connection:Disconnect()
		connection = nil
	end)

	-- start walking
	hum:MoveTo(targetPoint)
end

for _, node in ipairs(nodes) do
	moveTo(node.Position)
	
	
	repeat
		wait()
	until targetReached
end

I heard that there was a bug with that though on a another post. Pretty sure you just set their network owner to nil.

I’ll check it out once I’m on pc.

1 Like

For my game, I clone my zombies out of replicated storage and onto the path. Would I use that script on the clones or the ones in replicated storage?

i think you have to do it on the cloned zombies

I feel like it would make more sense doing it on the ones in replicated storage because when they get cloned, the clones also get the effect from it.

you can try both of the ways then

My bad, actually it only works on the cloned zombies because you can only change it to things in the workspace

It works though. Thanks a lot!

1 Like