Momentum Based System

Hello, ive recently created a wall runnning system but i cant figure out how to make it momentum based


Humanoid.StateChanged:Connect(function()
	if Humanoid:GetState() == Enum.HumanoidStateType.Freefall then
		OnGround = false
	elseif Humanoid:GetState() == Enum.HumanoidStateType.Landed or Humanoid:GetState() == Enum.HumanoidStateType.Climbing then
		OnGround = true
	end



end)

local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = {script.Parent}

HumanoidRootPart.Touched:Connect(function(hit)

	if OnGround then
		return
	end
if dbw then
	return
end

	if UIS:IsKeyDown(Enum.KeyCode.A) then

		local result = workspace:Raycast(HumanoidRootPart.Position,HumanoidRootPart.CFrame.RightVector * -10, raycastParams)
		if result then
			isrunning = true
			lloader:Play()
			local bodyve = Instance.new("BodyVelocity",HumanoidRootPart)
dbw = true
			bodyve.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			coroutine.resume(coroutine.create(function()
				repeat
					task.wait(0.1)
					if not bodyve then
						break
					end
					bodyve.Velocity = Vector3.new(result.Normal.Z,result.Normal.Y,result.Normal.X) * math.abs(Momentum)
				until bodyve == nil

			end))
			


			Humanoid.AutoRotate = false
		
			coroutine.resume(coroutine.create(function()
task.wait(1)
				repeat

					if UIS:IsKeyDown(Enum.KeyCode.Space) then
						isrunning = false
						bodyve:Destroy()
						lloader:Stop(
						)
						Humanoid.JumpPower = 150
						hum:ChangeState(Enum.HumanoidStateType.Jumping)
Humanoid.JumpPower = 50
					end
					task.wait()
				until not isrunning
				task.wait(1)
				dbw = false

			end))



			repeat

				local loopedres = workspace:Raycast(HumanoidRootPart.Position,HumanoidRootPart.CFrame.RightVector * -10, raycastParams)

				task.wait()
			until not loopedres or not UIS:IsKeyDown(Enum.KeyCode.A) or not isrunning
			bodyve:Destroy()
			lloader:Stop(
			)
			player.PlayerGui:WaitForChild("Smooth"):WaitForChild("Center"):Fire()
			Humanoid.AutoRotate = true
			isrunning = false
			task.wait(1)
			dbw = false

		end






	end

	if UIS:IsKeyDown(Enum.KeyCode.D) then

		local result = workspace:Raycast(HumanoidRootPart.Position,HumanoidRootPart.CFrame.RightVector * 10, raycastParams)
		if result then
			isrunning = true
			rloader:Play()
			local bodyve = Instance.new("BodyVelocity",HumanoidRootPart)
			player.PlayerGui:WaitForChild("Smooth"):WaitForChild("Right"):Fire()
			bodyve.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
			coroutine.resume(coroutine.create(function()
				repeat
					task.wait()
					if not bodyve then
						break
					end
					bodyve.Velocity = Vector3.new(result.Normal.Z,result.Normal.Y,result.Normal.X) * Momentum
				until bodyve == nil

			end))

			coroutine.resume(coroutine.create(function()
		
				repeat
					task.wait()
					if UIS:IsKeyDown(Enum.KeyCode.Space) then
						isrunning = false
						Humanoid.JumpPower = 150
						hum:ChangeState(Enum.HumanoidStateType.Jumping)
						Humanoid.JumpPower = 50

					end
					
				until not isrunning
				task.wait(1)
				dbw = false

			end))



			coroutine.resume(coroutine.create(function()


				repeat

					Momentum += 0.1

					task.wait(0.1)
				until not UIS:IsKeyDown(Enum.KeyCode.D) or not isrunning
			end))



			repeat

				local loopedres = workspace:Raycast(HumanoidRootPart.Position,HumanoidRootPart.CFrame.RightVector * 10, raycastParams)

				task.wait()
			until not loopedres or not UIS:IsKeyDown(Enum.KeyCode.D) or not isrunning
			bodyve:Destroy()
			rloader:Stop(
			)
			player.PlayerGui:WaitForChild("Smooth"):WaitForChild("Center"):Fire()
			Humanoid.AutoRotate = true
			isrunning = false
			task.wait(1)
			dbw = false

		end






	end
end)