I am attempting to make a click to move function with pathfinding and although it’s finding a path the player does not follow the path directly and instead skips to the last waypoints position.
Can I get some help I’m a bit of a noob to this?
local agentParams = {
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = false
}
mouse.Button1Down:Connect(function()
pos = mouse.Hit.Position
walkToPoint()
end)
function walkToPoint(x, z)
local goalX = x
local goalZ = z
local goalPosition = Vector3.new(x, 0, z)
local path = game:GetService("PathfindingService"):CreatePath(agentParams)
path:ComputeAsync(Char:WaitForChild("HumanoidRootPart").Position, pos)
local waypoints = path:GetWaypoints()
if path.Status == Enum.PathStatus.Success then
for _, waypoint in pairs(waypoints) do
local part = Instance.new("Part")
part.Shape = "Ball"
part.Material = "Neon"
part.Size = Vector3.new(0.6, 0.6, 0.6)
part.Position = waypoint.Position
part.Anchored = true
part.CanCollide = false
part.Parent = game.Workspace
DebrisService:AddItem(part, 8)
Humanoid:MoveTo(waypoint.Position)
wait()
end
else
-- [Pathing failed]
wait(1)
end
end