0
    local ZombieHumanoid = script.Parent.Zombie
local ZombieWizard = script.Parent
local Places = game.Workspace.PlacesEnemy

ZombieHumanoid.Died:Connect(function()
    ZombieWizard:Destroy()
end)

for Place=1, #Places:GetChildren() do
    ZombieHumanoid:MoveTo(Places[Place].Position)
    ZombieHumanoid.MoveToFinished:Wait()
end

The humanoid walks to the other place before it reaches it's target. Nothing really helps on youtube or any other website as the code doesn't work / fit in with this one. The code works with the other zombie which walkspeed is 10 but not with this wizard, which walkspeed is 5. Please help!

AronasRR
  • 23
  • 3

1 Answers1

2

Roblox has a core module implemented where if the humanoid does not reach its intended position in 8 seconds, the humanoid will void the operation and fire the MoveToFinished event, causing your zombie to start moving to its next location.

To work around this, try having more waypoints in between the two positions, or constantly call the :MoveTo() function and detect when it arrives by checking its distance between the waypoint. The following code should work to check its positions.

local zombieHumanoid = zombie.Humanoid -- set to ur humanoid
local positions = workspace.PlacesEnemy
local sensitivity = 5

for Place = 1, #Places:GetChildren() do
    local closeToWaypoint = false
    while not closeToWaypoint do
        ZombieHumanoid:MoveTo(Places[Place].Position)
        if (zombieHumanoid.Parent.PrimaryPart.Position - Places[Place].Position).Magnitude <= sensitivity then
            closeToWaypoint = true
        end
    wait(.5)
    end
end

The code above checks for the zombie's position and gets its average position between itself and the waypoint. If it is within 5 studs in magnitude, it will begin its route to the next waypoint. You can change the sensitivity of the code by changing the sensitivity value on top. By continuously calling :MoveTo(), it prevents Roblox from cancelling the moving process. If the zombie overshoots the waypoint constantly, change the wait() value at the bottom of the script to a lower value, though it is not recommended to go anywhere under 0.1 seconds.

Hope this helps and happy coding!

zeyuan2009
  • 36
  • 4