So I made an attempt to make a pathfinding Ai but, it will not jump. can someone help?




local humanoidrootpart = script.Parent:FindFirstChild("HumanoidRootPart")
local human = script.Parent:FindFirstChild("Humanoid")

function findTarget()
	local distant = 200
	local target = nil
	for i,v in pairs(workspace:GetChildren()) do
		local humanoid = v:FindFirstChild("Humanoid")
		local head = v:FindFirstChild("Head")
		if humanoid and head and v.Name ~= "wacky monster" then
			if (head.Position - humanoidrootpart.Position).magnitude < distant and humanoid.Health > 0 then
				distant = (head.Position - humanoidrootpart.Position).magnitude
				target = head
			end
		end
	end
	return target
end

while wait(0) do
	local head = findTarget()
	if head then
		local ray = Ray.new(humanoidrootpart.Position, (head.Position - humanoidrootpart.Position).Unit * 200)
		local hit,position = workspace:FindPartOnRayWithIgnoreList(ray,{script.Parent})
		if hit then
			hit:IsDescendantOf(head.Parent)
				human:MoveTo(head.Position)
		else
			human:MoveTo(head.Position)
			wait(.4)
			local path = game:GetService("PathfindingService"):FindPathAsync(humanoidrootpart.Position,head.Position)
			local points = path:GetWayPoints()
			if path.Status == Enum.PathStatus.Success then
			for i,v in pairs(points) do
				human:MoveTo(v.Position)
				human:MoveToFinished()
				wait(2)
				
				if v.Action == Enum.PathWaypointAction.Jump then
					human.Jump = true
				end
				if (points[#points].Position - head.Position).magnitude > 15 then
					break
				end
			end
			else
				human:MoveTo(head.Position)
			end
		end
	end
end



3 comments

0

This use of waypoints is all wrong. MoveToFinished is an event, not a function. You're meant to call MoveTo on the first waypoint, and then wait until you arrive (or nearly arrive) to call it on the next one. Repeat this until you arrive at the last one.

0

ok

0

so do I remove MoveToFinished()?