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)