Converting ContextActionService to UserInputService for Fly Script

Hi! I have a fly script that I made by following a tutorial. Everything works well except that It uses ContextActionService to receive the inputs from the player. For organizing purposes I would like to use UserInputService instead but I have no idea how I would even begin to convert the script to using UIS instead of CAS, any ideas?

Heres my fly script

--Assets
local ContextActionService = game:GetService("ContextActionService")
local RunService = game:GetService("RunService")
local Connection = nil
local Character = script.Parent
local PrimaryPart = Character.PrimaryPart
local VectorForce = script:WaitForChild("VectorForce")
VectorForce.Attachment0 = PrimaryPart.RootRigAttachment
local AlignOrientation = script:WaitForChild("AlignOrientation")
AlignOrientation.Attachment0 = PrimaryPart.RootRigAttachment
local GravityVector = Vector3.new(0,workspace.Gravity,0)
local Drag = 1
local Force = 150
local Yaxis = 0
local Cooldown = false
local Fallrate = 100
local MaxHeight = 150
local Ended = false
local CooldownTime = 5

---Script

local function FlyAction(ActionName, InputState, InputObject)
	if InputState ~= Enum.UserInputState.Begin then return Enum.ContextActionResult.Pass end
	if Connection == true then  return Enum.ContextActionResult.Pass end
	if Cooldown and Ended then return Enum.ContextActionResult.Pass end
	if Connection == nil then
		
		Ended = false
		Cooldown = true
		coroutine.wrap(function()
			task.wait(CooldownTime)
			Cooldown = false
		end)()
		Connection = true
		--PrettyShit Goes here
		task.wait(1.5)
		if Character.Humanoid.FloorMaterial ~= Enum.Material.Air then
			Character.Humanoid:ChangeState(Enum.HumanoidStateType.Jumping)
			task.wait(0.1)
		end
		VectorForce.Enabled = true
		AlignOrientation.CFrame = PrimaryPart.CFrame
		AlignOrientation.Enabled = true
		Character.Humanoid:ChangeState(Enum.HumanoidStateType.Physics)
	
		Connection = RunService.Heartbeat:Connect(function(deltaTime)
	
			VectorForce.Force = GravityVector * PrimaryPart.AssemblyMass
			local MoveVector = Vector3.new(Character.Humanoid.MoveDirection.X, Yaxis, Character.Humanoid.MoveDirection.Z)
			if PrimaryPart.Position.Y >= MaxHeight then
				MoveVector = Vector3.new(Character.Humanoid.MoveDirection.X, 0, Character.Humanoid.MoveDirection.Z)
			end
			
			if MoveVector.Magnitude > 0 then	
				MoveVector = MoveVector.Unit
				VectorForce.Force += MoveVector * Force * PrimaryPart.AssemblyMass
				if math.abs(MoveVector.Y) == 1 then
					AlignOrientation.CFrame = CFrame.lookAt(Vector3.new(0,0,0), MoveVector,-PrimaryPart.CFrame.LookVector) * CFrame.fromOrientation(-math.pi/2,0,0)
				else
					AlignOrientation.CFrame = CFrame.lookAt(Vector3.new(0,0,0), MoveVector) * CFrame.fromOrientation(-math.pi/2,0,0)
				end
			else	
				AlignOrientation.CFrame = CFrame.fromMatrix(Vector3.zero, PrimaryPart.CFrame.RightVector, Vector3.yAxis)				
			end
			
			if PrimaryPart.AssemblyLinearVelocity.Magnitude > 0 then
				local DragVector = -PrimaryPart.AssemblyLinearVelocity.Unit * PrimaryPart.AssemblyLinearVelocity.Magnitude ^ 1.5			
				VectorForce.Force += DragVector * Drag * PrimaryPart.AssemblyMass 
			end
			
			VectorForce.Force -= Vector3.new(0,Fallrate,0) 
		end)
	else
		VectorForce.Enabled = false
		AlignOrientation.Enabled = false
		Character.Humanoid:ChangeState(Enum.HumanoidStateType.Freefall)
		Connection:Disconnect()
		Connection = nil
		Ended = true
		
	end
	return Enum.ContextActionResult.Pass
end

local function UpAction(ActionName,InputState,InputObject)
	
	if InputState == Enum.UserInputState.Begin then Yaxis = 1 else Yaxis = 0 end
	return Enum.ContextActionResult.Pass
end

ContextActionService:BindAction("Fly", FlyAction, true, Enum.KeyCode.R)
ContextActionService:BindAction("Up",UpAction,true,Enum.KeyCode.Space)

Heres The type of UIS in trying to convert this function into that will then run in a module script.

--Services
local Replicated = game:GetService('ReplicatedStorage')
local UIS = game:GetService('UserInputService')

--Character/Player
local Players = game:GetService('Players')
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()
local Humanoid = Character:WaitForChild('Humanoid')
local Animator = Humanoid:WaitForChild('Animator')
local PrimaryPart = Character.PrimaryPart
local Mouse = Player:GetMouse()

--Assets
local LightMagicRemote = Replicated.Assets.Remotes.LightMagicRemote
local QDebounce = false
local EDebounce = false
local RDebounce = false

--Body
UIS.InputBegan:Connect(function(input,gameProcessedEvent)
	if gameProcessedEvent or QDebounce then return end
	if input.KeyCode == Enum.KeyCode.Q then
		
		LightMagicRemote:FireServer("Q")
		QDebounce = true
		task.wait(10)
		QDebounce = false
	end
end)

Why are you trying to change it to UserInputService? ContextActionService is way better to use for these types of scripts. It would be much better to stick with CAS than porting it over to UIS for no reason and getting a worse result.

Its just for organizing purposes, the rest of modules and abilities use UIS so it would be odd to me if had this one ability use CAS as the exception.