So i was making this flying script, it works fine but theres some annoying bugs that i can't seem to get rid of, the flying script is based on keybinds so WASD, Space and CTRL, once i try to combine keys like W and D to go diagonally it starts this glitchy and weird bug where the character seems to be going diagonally but its spazzing out and not really functioning smoothly, is there a way to combine the keys smoothy, i tried adding the Velocity but that made you go faster as you holded the button, so setting it is my only option for right now.
Script -
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")
local SpaceHolded = false
local ControlClick = false
local SpaceClick = false
local Forward = false
local Backwards = false
local Character = player.Character
local flying = false
player.Character.Humanoid.StateChanged:Connect(function(old, new)
print("0")
if (new == Enum.HumanoidStateType.RunningNoPhysics or new == Enum.HumanoidStateType.Running) then
print("1")
if flying == true then
local BV = Character.HumanoidRootPart:FindFirstChild("Flying")
game.Debris:AddItem(BV, 0.1)
flying = false
SpaceClick = false
ControlClick = false
print("flying stop")
end
end
end)
UIS.InputBegan:Connect(function(input, IT)
if IT then return end
if input.KeyCode == Enum.KeyCode.Space and flying == false then
if Character.Humanoid.FloorMaterial ~= Enum.Material.Air then return end
SpaceHolded = true
flying = true
spawn(function()
wait(0.5)
SpaceHolded = false
end)
wait(0.3)
if SpaceHolded == true then
SpaceHolded = false
local BV = Instance.new("BodyVelocity", Character.HumanoidRootPart)
BV.Name = "Flying"
BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BV.Velocity = Vector3.new(0,6,0)
spawn(function()
wait(0.4)
BV.Velocity = Vector3.new(0,0,0)
end)
end
elseif input.KeyCode == Enum.KeyCode.Space and flying == true then
SpaceClick = true
local BV = Character.HumanoidRootPart:FindFirstChild("Flying")
while SpaceClick == true do
wait()
repeat wait() until BV
BV.Velocity = Character.HumanoidRootPart.CFrame.upVector * 30
end
BV.Velocity = BV.Velocity / 2
wait(0.2)
BV.Velocity = BV.Velocity / 4
wait(0.2)
BV.Velocity = Vector3.new(0,0,0)
elseif input.KeyCode == Enum.KeyCode.LeftControl and flying == true then
ControlClick = true
local BV = Character.HumanoidRootPart:FindFirstChild("Flying")
while ControlClick == true do
wait()
repeat wait() until BV
BV.Velocity = Character.HumanoidRootPart.CFrame.upVector * -30
end
BV.Velocity = BV.Velocity / 4
wait(0.2)
BV.Velocity = Vector3.new(0,0,0)
elseif input.KeyCode == Enum.KeyCode.W and flying == true then
Forward = true
local BV = Character.HumanoidRootPart:FindFirstChild("Flying")
while Forward == true do
wait()
repeat wait() until BV
BV.Velocity = Character.HumanoidRootPart.CFrame.lookVector * 30
end
BV.Velocity = BV.Velocity / 2
wait(0.2)
BV.Velocity = BV.Velocity / 4
wait(0.2)
BV.Velocity = Vector3.new(0,0,0)
elseif input.KeyCode == Enum.KeyCode.S and flying == true then
Backwards = true
local BV = Character.HumanoidRootPart:FindFirstChild("Flying")
while Backwards == true do
wait()
repeat wait() until BV
BV.Velocity = Character.HumanoidRootPart.CFrame.lookVector * -30
end
BV.Velocity = BV.Velocity / 2
wait(0.2)
BV.Velocity = BV.Velocity / 4
wait(0.2)
BV.Velocity = Vector3.new(0,0,0)
end
end)
UIS.InputEnded:Connect(function(input, IT)
if IT then return end
if input.KeyCode == Enum.KeyCode.Space and flying == true and SpaceClick == true then
SpaceClick = false
elseif input.KeyCode == Enum.KeyCode.Space then
SpaceHolded = false
elseif input.KeyCode == Enum.KeyCode.LeftControl and flying == true and ControlClick == true then
ControlClick = false
elseif input.KeyCode == Enum.KeyCode.W and flying == true and Forward == true then
Forward = false
elseif input.KeyCode == Enum.KeyCode.S and flying == true and Backwards == true then
Backwards = false
end
end)
