------------------------------------------------------------------------------------------------------------------------------------------------------
--  Functions
------------------------------------------------------------------------------------------------------------------------------------------------------


local function CreatePath()
	if not LocalMouse.Target then return end

	local Origin 	= LocalCharacter:FindFirstChild('HumanoidRootPart').Position
	local Target 	= Vector3.new(LocalMouse.Hit.X, LocalMouse.Hit.Y, LocalMouse.Hit.Z)
	local Path 		= PathfindingService:ComputeSmoothPathAsync(Origin, Target, 512)

	assert(Path.Status == Enum.PathStatus.Success, 'Pathfinding failed')
	CurrentPath = Path

	for Index, Point in next, Path:GetPointCoordinates() do
		local Distance = nil
		LocalCharacter:WaitForChild('Humanoid'):MoveTo(Point)

		repeat
			wait()
			Distance = (Point - LocalCharacter:WaitForChild('HumanoidRootPart').Position).magnitude
		until Distance <= 4.5 or Path ~= CurrentPath
		
		if Path ~= CurrentPath then break end
	end 
end 
