Need help with a velocity based fall-damasge script

I want to make a fall damage script and I do have one that works decently

--height at which the player starts to take damage
local minimumDamageHeight = 25
--height at which the player takes maximumDamage damage
local maximumDamageHeight = 200
--if height exceeds maximumDamageHeight,
--player will take over maximumDamage damage
local maximumDamage = 100

local velocity

-- linear interpolation function
local function lerp(a,b,t)
	return (1-t)*a+b*t
end

--inverse of lerp function
local function invLerp(a,b,v)
	return (v-a)/(b-a)
end

--remaps value, used for max and min damage heights.
local function remap(iMin,iMax,oMin,oMax,v)
	return lerp(oMin,oMax,invLerp(iMin,iMax,v))
end

-- fired when FloorMaterial changes
script.Parent.Humanoid:GetPropertyChangedSignal("FloorMaterial"):Connect(function()
	--calculate fall height from velocity
	local height = (velocity * velocity)/(2*workspace.Gravity)

	--remap damage based on variables
	local damage = remap(minimumDamageHeight,maximumDamageHeight,0,maximumDamage,height)
	--prevent negative damage
	damage = math.max(damage,0)
	--apply damage
	script.Parent.Humanoid:TakeDamage(damage)
end)

--fires before each physics update
game:GetService("RunService").Stepped:Connect(function(time,step)
	--update velocity variable
	velocity = script.Parent.HumanoidRootPart.Velocity.Y
end)

but I have this dash script. When I use it midair, it cancels out my fall damage, here it is for reference:

local UIS = game:GetService("UserInputService")

local camera = workspace.CurrentCamera
local DKeyDown = false
local SKeyDown = false
local AKeyDown = false
local WKeyDown = false



local Blocking = false


local Player = game.Players.LocalPlayer
local Char = Player.Character or Player.CharacterAdded:Wait()
while Char.Parent == nil do
	Char.AncestryChanged:wait()
end
local HumRP = Char:WaitForChild("HumanoidRootPart")
local Hum = Char:WaitForChild("Humanoid")
local RollFrontAnim = Hum:LoadAnimation(script:WaitForChild("RollFront"))
local BackRollAnim = Hum:LoadAnimation(script:WaitForChild("BackRoll"))
local LeftRollAnim = Hum:LoadAnimation(script:WaitForChild("RightRoll"))
local RightRollAnim = Hum:LoadAnimation(script:WaitForChild("LeftRoll"))
local DashDebounce = false
local DashingDebounce = false
local CanDoAnything = true
local d = script.Dash
local d2 = script.Dash
local d3 = script.Parent:WaitForChild("DashL")
local char = script.Parent.Parent
UIS.InputBegan:Connect(function(Input,IsTyping)
	if IsTyping then return end
	if Char:FindFirstChild("PBSTUN") then return end

	if Char:FindFirstChild("noJump") then return end
	if CanDoAnything == true  then
		if Input.UserInputType == Enum.UserInputType.MouseButton1 then
			
		elseif Input.KeyCode == Enum.KeyCode.Q then
			
			if DashDebounce == false and Char:FindFirstChild("Disabled") == nil and char:GetAttribute("Stunned") == false then
				game.ReplicatedStorage.Events.UpdateAttribute:FireServer("SwingCooldown",true)
				DashDebounce = true
				CanDoAnything = false
				game.ReplicatedStorage.Events.UpdateAttribute:FireServer("Dashing",true)
				delay(0.3,function()
					CanDoAnything = true
				end)
				delay(1,function()
					DashDebounce = false
				end)
				if WKeyDown then
					RollFrontAnim:Play()
					DashingDebounce = true
					d:Play()
					game.ReplicatedStorage.Events.UpdateAttribute:FireServer("iframes",true)
					delay(0.25,function()
						DashingDebounce = false
					end)
					
					repeat
							HumRP.Velocity = HumRP.CFrame.lookVector * 80
							wait(0.1)
						
						
					until DashingDebounce == false
				elseif SKeyDown then
					DashingDebounce = true
					
					BackRollAnim:Play()
					d:Play()
					game.ReplicatedStorage.Events.UpdateAttribute:FireServer("iframes",true)
					delay(0.25,function()
						DashingDebounce = false
					end)

					repeat
						
						HumRP.Velocity = HumRP.CFrame.lookVector * -110
						wait(0.1)
					until DashingDebounce == false
				elseif DKeyDown then
					DashingDebounce = true
					
					LeftRollAnim:Play()
					d2:Play()
					game.ReplicatedStorage.Events.UpdateAttribute:FireServer("iframes",true)
					delay(0.25,function()
						DashingDebounce = false
					end)

					repeat
					
						HumRP.Velocity = HumRP.CFrame.rightVector * 100
						wait(0.11)
					until DashingDebounce == false
				elseif AKeyDown then
					DashingDebounce = true
					d2:Play()
					game.ReplicatedStorage.Events.UpdateAttribute:FireServer("iframes",true)
					RightRollAnim:Play()
					
					
					delay(0.25,function()
						DashingDebounce = false
					end)

					repeat
						
						HumRP.Velocity = HumRP.CFrame.rightVector * -100
						wait(0.11)
					until DashingDebounce == false
				end	
				game.ReplicatedStorage.Events.UpdateAttribute:FireServer("iframes",false)
				game.ReplicatedStorage.Events.UpdateAttribute:FireServer("Dashing",false)
				task.delay(0.3,function()
					game.ReplicatedStorage.Events.UpdateAttribute:FireServer("SwingCooldown",false)
				end)
			end	
			
	
			end
		end
	end)

local RunService = game:GetService("RunService")

RunService.RenderStepped:Connect(function()
	local Player = game.Players.LocalPlayer
	local Char = Player.Character
	local Hum = Char:FindFirstChild("Humanoid")
	
	if UIS:IsKeyDown(Enum.KeyCode.W)  then
		WKeyDown = true
	else
		WKeyDown = false
	end
	if UIS:IsKeyDown(Enum.KeyCode.A)  then
		AKeyDown = true
	else
		AKeyDown = false
	end
	if UIS:IsKeyDown(Enum.KeyCode.S) then
		SKeyDown = true
	else 
		SKeyDown = false
	end
	if UIS:IsKeyDown(Enum.KeyCode.D) then
		DKeyDown = true
	else 
		DKeyDown = false
	end
	

end)

I was wondering how to make a script that applies fall damage when your velocity suddenly changes, not when you hit the ground. Similar to how deepwoken’s fall damage system works. If anyone has a script or idea for this, please repond.