Explanation:

For a couple of days, I've been learning how to make a ledge grab and a wall jump system and have gotten a fairly decent understanding. But I've run into some quality-of-life things for the code that I want to tackle. So far, the script below will only work properly (e.x: find a ledge proper ledge and wall) if I put it in a loop. I wanted to see if I could make the code look better without the loop because if I remove the loop, I simply will only get the wall. Can I get a hand with this?

Code:

-- Ledge Detection
local ledge = false
local point1 = root.CFrame.p
local point2 = root.CFrame.lookVector * 5
									
local orientation = false
local rot = character.HumanoidRootPart.CFrame - character.HumanoidRootPart.CFrame.p
									
for i = 1, 25 do
	point1 = point1 + Vector3.new(0, .3, 0)
	point2 = point2 + Vector3.new(0, .3, 0)
	local ray = Ray.new(point1, point2)
	local hit, pos, normal = workspace:FindPartOnRay(ray, game.Workspace.Living)
	if pos and hit and (hit.Name ~= "Branches" or hit.Name ~= "Leaves" or hit.Name ~= "BranchPart") then
		if hit.Name ~= "NoClimb" or hit.Name ~= "No_Climb" then
			if not orientation then
				orientation = pos
			end
		end
	end
	if not hit and orientation then
		ledge = true
	end
end
									
-- Decision
if hit then
Remotes.Inputs:FireServer(plr, {Type = "Special", Button = "Wall"});
if not ledge then
	print("Wall")
	-- Body Pos + Body Velocity
else
	print("Ledge")
	-- Body Pos + Lerp Or Tween
	end
end