Fly script stop when second input is release

so I have this fly script and the problem is that while moving when i let go of another movement key, my fly script will resets its position, it makes the fly script feel linear

i want to be able to fly while pressing the w and a key or w and or d key to move freely without flying stopping. I’ve tried debounce, bool values but it doesn’t seem to work how can I fix this.

i’ve simpelfied the code to make it more readible

local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local c = Player.Character
local mouse = Player:GetMouse()
Tool = script.Parent
local UIS = game:GetService("UserInputService")
local RS = game:GetService("RunService")
local Enabled = true
local active =  false
local camera = game.Workspace.CurrentCamera
local HRP = c:FindFirstChild("HumanoidRootPart")                                             
uis = game:GetService("UserInputService") --- IDLE
rs = game:GetService("ReplicatedStorage")


uis.InputBegan:Connect(function(input,IsTpying)
	if input.keyCode ==  Enum.KeyCode.F and IsTpying == false then -- enabling fly script
		if active ==  false then
			script.RemoteEvent:FireServer("Flying")
			local part = HRP:WaitForChild("Part")
			local AO = HRP:WaitForChild("AO")
			
			local Oo = part.Orientation
			local Op = part.Position
			
			
			game:GetService("RunService").RenderStepped:Connect(function()
				part.CFrame = CFrame.new(HRP.Position, camera.CFrame.LookVector.Unit * 1e8)
			end)
			
			
			local function movementBind(actionName, inputState)
				if (inputState == Enum.UserInputState.Begin) then
					
					if actionName == "forward" then	
					
					part.Attachment.CFrame = part.Attachment.CFrame * CFrame.new(0,0,-50)
						
					elseif actionName == "backward" then
								
						part.Attachment.CFrame = part.Attachment.CFrame * CFrame.new(0,0, 50)
					
					elseif actionName == "left" then
						
						part.Attachment.CFrame = part.Attachment.CFrame * CFrame.new(-50,0,0) 
						
					elseif actionName == "right" then
										
						part.Attachment.CFrame = part.Attachment.CFrame * CFrame.new(50,0,0)
					end
					
				elseif (inputState == Enum.UserInputState.End) then -- Problem 
						
						part.Position = Op
		
					
				end   
			end
			
				game:GetService("ContextActionService"):BindAction("forward", movementBind, false, Enum.PlayerActions.CharacterForward);
				game:GetService("ContextActionService"):BindAction("backward", movementBind, false, Enum.PlayerActions.CharacterBackward);
				game:GetService("ContextActionService"):BindAction("left", movementBind, false, Enum.PlayerActions.CharacterLeft);
				game:GetService("ContextActionService"):BindAction("right", movementBind, false, Enum.PlayerActions.CharacterRight);
			
 
			
		end
	end
end)

Have you tried a while loop?

For example, you can have it detect the input and set a bool value (let’s use “IsFlying” as an example) to true. When the input is pressed again, it will set IsFlying to false.

Then, add a loop outside of the uis.InputBegan function as: while IsFlying do and the contents should be your flying components. Let me know if you would like some code if this does not make sense.

yeah i would like to see an example please

i think i worded my premise wrong the point is that im trying to make is when i let go any of my movement input the flying script stops and i float midair until i press the movement key again to move.

so when i hold the W key i would move forward and when i try to hold the W key with the D key i would move forward and right (diagonal right direction) but as soon as i let go of the D key instead of flying forward because im still holding the w key i simply float midair until I have to press the w key again.

ik this sounds really weird and i’m trying my best to make it sound easy as possible lol

Hmm that is interesting… I had the wrong idea at first, I’m not too sure now…