Help with roblox's pathfinding service!

Hey there! Ive been trying to create some enemy AI, and I’m currently making it so that when an enemy finds a player in its range, it will follow the player using its pathfinding service, though when I try to play it, the rig follows the player’s point, walks to it, then updates the players position. Currently, I have a script that moves the rig, and a module script that creates the code to move the rig.
https://gyazo.com/8e2912698c1d409bb5c159500c8fc189

SCRIPT~

task.spawn(function()
	while task.wait(0.1) do
		enemy.FollowPlayer(game.Players.forkyplayss.Character, workspace.enemy)
	end
end)

(using my own character for testing)
MODULE SCRIPT~

function enemy.FollowPlayer(plr, enemy)
	local hum = enemy:WaitForChild("Humanoid")
	local torso = enemy:WaitForChild("Torso")
	local root = hum.Parent.PrimaryPart

	if hum then
		local path = pathfinding:CreatePath()
		path:ComputeAsync(torso.Position, plr:WaitForChild("HumanoidRootPart").Position)
		local points = path:GetWaypoints()
		for i, waypoint in pairs(points) do
			if waypoint.Action == Enum.PathWaypointAction.Jump then
				hum:ChangeState(Enum.HumanoidStateType.Jumping)
			end
			hum:MoveTo(waypoint.Position)
			hum.MoveToFinished:Wait()

		end
	else
		warn("no humanoid loaded!")
	end
end

If anyone could help, it would be greatly appreciated!!

1 Like