-- ================================================================================
-- LOCAL FUNCTIONS
-- ================================================================================

local function UpdateDirection(arrow, targets)
	if targets == 0 then return end
	
	local checkpoint = targets[1]:FindFirstChild("Checkpoint")
	local closestDistance = (arrow.Position - checkpoint.Position).magnitude
	local closestTarget = checkpoint
	
	-- Find nearest target
	for _, target in ipairs(targets) do
		checkpoint = target:FindFirstChild("Checkpoint")
		local distance = (arrow.Position - checkpoint.Position).magnitude
		if distance < closestDistance then
			closestTarget = checkpoint
		end
	end
	
	-- Point arrow at nearest target
	arrow.CFrame = CFrame.new(arrow.Position, closestTarget.Position)
end -- UpdateDirection()