Ledge Grab Issue

I have a double jump script and a ledge grab script. If you jump it will grab the ledge but for some reason if you double jump it wont grab the ledge. If anyone could please fix one of my scripts thats would be a big help.

Ledge Grab Script:

local plr = game.Players.LocalPlayer
local Character = plr.Character or plr.CharacterAdded:Wait()
local Root = Character:WaitForChild("HumanoidRootPart")
local Head = Character:WaitForChild("Head")
local Hum = Character:WaitForChild("Humanoid")
local CA = Hum:LoadAnimation(script:WaitForChild("ClimbAnim"))
local HA = Hum:LoadAnimation(script:WaitForChild("HoldAnim"))
local TouchGui = plr:WaitForChild("PlayerGui"):FindFirstChild("TouchGui")
local UIS = game:GetService("UserInputService")

ledgeavailable = true
holding = false
while game:GetService("RunService").Heartbeat:Wait() do
	local r = Ray.new(Head.CFrame.p, Head.CFrame.LookVector * 5)
	local part,position = workspace:FindPartOnRay(r,Character)
	if part and ledgeavailable and not holding then
		if part.Size.Y >= 7 then
			if Head.Position.Y >= (part.Position.Y + (part.Size.Y / 2)) - 1 and Head.Position.Y <= part.Position.Y + (part.Size.Y / 2) and Hum.FloorMaterial == Enum.Material.Air and Root.Velocity.Y >= 0 then
				Root.Anchored = true holding = true HA:Play() ledgeavailable = false
			end
		end
	end
	
	function climb()
		local Vele = Instance.new("BodyVelocity",Root)
		Root.Anchored = false Vele.MaxForce = Vector3.new(1,1,1) * math.huge Vele.Velocity = Root.CFrame.LookVector * 10 + Vector3.new(0,30,0)
		HA:Stop() CA:Play()
		game.Debris:AddItem(Vele,.15) holding = false
		wait(.75)
		ledgeavailable = true
	end
	
	UIS.InputBegan:Connect(function(Key,Chat)
		if not holding then return end
		if Key.KeyCode == Enum.KeyCode.Space and not Chat then
			climb()
		end
	end)
	
	if TouchGui then
		TouchGui:WaitForChild("TouchControlFrame"):WaitForChild("JumpButton").MouseButton1Click:Connect(function()
			if not holding then return end
			climb()
		end)
	end
end

Both Double Jump Scripts:

local MaxJumps = 2
local JumpCooldown = 0.2

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local NumJumps = 0
local canjump = false

local jumpanimation = script:WaitForChild("JumpAnimation")
local jumptrack = Humanoid:LoadAnimation(jumpanimation)

local sound = Instance.new("Sound")
sound.Volume = 3
sound.SoundId = "rbxassetid://9120972724"
sound.Parent = game:GetService("SoundService")

Humanoid.StateChanged:Connect(function(oldstate, newstate)
	if Enum.HumanoidStateType.Landed == newstate then
		
		NumJumps = 0
		canjump = false
		
	elseif Enum.HumanoidStateType.Freefall == newstate then
		
		wait(JumpCooldown)
		canjump = true
		
	elseif Enum.HumanoidStateType.Jumping == newstate then
		
		canjump = false
		NumJumps = NumJumps + 1
		
	end
end)

UIS.JumpRequest:Connect(function()
	if canjump and NumJumps < MaxJumps then
		Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
		
		local newtag = Instance.new("StringValue")
		newtag.Parent = Char
		newtag.Name = "InDoubleJump"
		
		sound:Play()
		jumptrack:Play()
		
		game:GetService("Debris"):AddItem(newtag, 0.1)
	end
end)

UIS.InputBegan:connect(function(input)
	if input.KeyCode == Enum.KeyCode.E then
		jumptrack:Stop()
		jumpanimation:Stop()
	end
end)

if Enum.HumanoidStateType.Landed then
	jumptrack:Stop()
end
local MaxJumps = 2
local JumpCooldown = 0.1

local UIS = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Char:WaitForChild("Humanoid")
local NumJumps = 0
local canjump = false

local sound = Instance.new("Sound")
sound.Volume = 1.2
sound.PlaybackSpeed = 1.25
sound.SoundId = "rbxassetid://7313871678"
sound.Parent = game:GetService("SoundService")

local newparticles1 = game:GetService("ReplicatedStorage").JumpParticles:Clone()
newparticles1.Parent = Char:WaitForChild("LeftFoot")

local newparticles2 = game:GetService("ReplicatedStorage").JumpParticles:Clone()
newparticles2.Parent = Char:WaitForChild("RightFoot")

Humanoid.StateChanged:Connect(function(oldstate, newstate)
	if Enum.HumanoidStateType.Jumping == newstate then
		
		if not Char:FindFirstChild("InDoubleJump") then
			sound:Play()
		end

		newparticles1.Enabled = true
		newparticles2.Enabled = true
		wait(0.2)
		newparticles1.Enabled = false
		newparticles2.Enabled = false
		
	elseif Enum.HumanoidStateType.Landed == newstate then
		newparticles1.Enabled = false
		newparticles2.Enabled = false
	end
end)

UIS.JumpRequest:Connect(function()
	if canjump and NumJumps < MaxJumps then
		local JumpTrack = Humanoid:LoadAnimation(script.Jump)
		JumpTrack:Play()
		
		Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
	end
end)