hello.

I'm making a pathfinding system, and I want it to be able to track humanoids without using the normal drooling zombie scripts. although I have a system that can pathfind a maze, the system I made only has it pathfind to where the humanoid was, not where it is, so to have it get the the humanoid, it has to stop moving.

local pathfindingservice = game:GetService("PathfindingService")
local ve = script.degrees

local RangeInStuds = 30

local characters = {""}

game.Players.PlayerAdded:Connect(function(plr)
	local char = game.Workspace:WaitForChild(plr.Name)
	table.insert(characters, #characters+1, char.Name)
	print(char.Name)
	print(characters[#characters])
end)

local orig = script.Parent.orig
local endthing = script.vec
local human = script.Parent:WaitForChild("Humanoid")
local torso = script.Parent:WaitForChild("Torso")

---Newpathscriptbit

local sc = script.Parent.DetectorPart:FindFirstChildOfClass("Script")
local rep = game.ReplicatedStorage
local par = script.Parent.DetectorPart

sc:Destroy()
local sc2 = rep.NewNewPath:Clone()
sc2.Parent = par

local path = pathfindingservice:CreatePath()

path:ComputeAsync(torso.Position,endthing.Value)

local waypoints = path:GetWaypoints()
		
for i, waypoint in pairs (waypoints) do
	if waypoint.Action == Enum.PathWaypointAction.Jump then
		human:ChangeState(Enum.HumanoidStateType.Jumping)
	end
	
	for i, near in pairs(game.Players:GetChildren()) do
		if near.Character then
			local character = near.Character
			local charpos = character.Torso.Position
			local mobpos = script.Parent.Torso.Position
			local mag = (mobpos-charpos).Magnitude
			if mag <= RangeInStuds then
				local newpos = Vector3.new(charpos.X, charpos.Y, charpos.Z)
				script.vec.Value = newpos
			else
				script.vec.Value = orig.Value
			end
		end
	end
		
	human:MoveTo(waypoint.Position)
	human.MoveToFinished:Wait(2)
end

so this is my script(some of the stuff is probably unnecessary, but I'm too lazy to go through it and clean it up right now), and I'd really like it if people would share they're knowledge, thanks as always.

3 comments

0

You can make the zombie check on each waypoint loop if the player position changed from the old one ((oldPos-player.Position).magnitude > 10) to break the loop and recalculate. You can also check on that loop if a ray from the zombie to the player is blocked, and if it isn't, you break the loop and make the zombie move towards the player for sometime.

0

You would have to make a loop that calculates the path and the things i mentioned before, else it will stop moving after the first time he ends walking the path.

0

To loop to see if they player pos is close enough to the mob pos, wouldnt i also have to loop through the players still because i need all of them, not just having it so it can only track one player?