Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

??? I cant make a zombie follow a player using pathfinding and i need help

I actually need help with pathfinding for a zombie follow a player, and i searched in alot of places but i didn't find it, and here is my script:

local Humanoid = script.Parent.Humanoid


local RootPart = script.Parent.HumanoidRootPart

function findNearestPlayer(Position)
    wait(0.3)
    local List = game.Workspace:children()
    local Torso = nil
    local Distance = 500
    local Temp = nil
    local Human = nil
    local Temp2 = nil
    for x = 1, #List do
        Temp2 = List[x]
        if (Temp2.className == "Model") and (Temp2 ~= script.Parent) then
            Temp = Temp2:findFirstChild("HumanoidRootPart")
            Human = Temp2:findFirstChild("Humanoid")
            if (Temp ~= nil) and (Human ~= nil) and (Human.Health > 0) then
                if (Temp.Position - Position).magnitude < Distance then
                    Torso = Temp
                    Distance = (Temp.Position - Position).magnitude
                end
            end
        end
    end
    return Torso
end
 
 
 
 
while true do
    local target = findNearestPlayer(script.Parent.HumanoidRootPart.Position)
	if target ~= nil then
		
		local Path = game:GetService("PathfindingService"):CreatePath()
		Path:ComputeAsync(RootPart.Position,target)
		
		local waypoints = Path:GetWaypoints()
		script.Parent.Humanoid:MoveTo(RootPart.Position,waypoints.Position)
		Humanoid.MoveToFinished:Wait()
    end
end

1 answer

Humanoid.MoveToFinished:Wait()

Try replacing this with

Humanoid.MoveToFinished:Wait(2)
-- or 5!

I've only had one experience with pathfinding, and I'm confused on where to look based on the information given, so I apologize if this is not correct.

This discussion is preserved as it was. New answers, comments, and votes are closed.