Need help with conflicting functions

Hey guys,

Basically I have 2 functions. 1 latches the player to a wall when the press space, and the other is a double jump function that also relies on space.

Here is the latch one (uses raycasting and if it hits, then the player teleports to that spot):

Summary
UIS.InputEnded:Connect(function(input)
	if (Controller.StateTracker.State == "onFreeFall" or Controller.StateTracker.State == "onJumping") and input.KeyCode == Enum.KeyCode.Space then
		print("------------------------------space noticed")
		humanoid.JumpPower = 0

		-- Call the function to latch
		latch()

	end
end)

Here is the double jump:

Summary
local canDoubleJump = false
local hasDoubleJumped = false
local oldPower = 50
local jump_multi = 1.5

function onJumpRequest()
	if not character or not humanoid or not character:IsDescendantOf(workspace) then
		return
	end
	

	if (Controller.GravityUp-Vector3.new(0,1,0)).Magnitude < .1 then					
		if canDoubleJump and not hasDoubleJumped then
			print("DOUBLE JUMP SHOULD HAVE HAPPENED-----------------------------------")
			hasDoubleJumped = true
			humanoid.JumpPower = oldPower * jump_multi
			humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			wait()
			humanoid.PlatformStand = true
			humanoid.JumpPower = 0
		end
	end
end

local function characterAdded(new)

	hasDoubleJumped = false
	canDoubleJump = false
	oldPower = humanoid.JumpPower
	
	
	StateTracker.Changed:Connect(function(old, new)
		if StateTracker.State == "onRunning" or StateTracker.State == "onGravityWalk" then
			canDoubleJump = false
			hasDoubleJumped = false
			humanoid.JumpPower = 0
			humanoid.PlatformStand = true
		elseif StateTracker.State == "onFreeFall" then
			wait()
			canDoubleJump = true
			hasDoubleJumped = false
		end
	end)
end

if player.Character then
	characterAdded(player.Character)	
end

I believe the best option is to only have the Double Jump work if the latch function has not hits;

or to somehow merge these two together (which I have tried multiple times but cannot seems to figure it out).

If anyone can get me moving on the right track that’ll be great!

put them both in the same script, and make them a function so you have
function dubblejump() and ‘function wallgrab ()’

now create the function that choses wich one to use

Right they are both in the same script already.

Figuring out how to make the script choose which one to use is what I am stuck on.

Edit:

They both happen off of InputEnded.

I want the latch function to player first and if the raycast does not hit, then the double to happen.