Im making a flying system. all was working well but for some reason, i can only move downward
I used a video for reference since im new to flight systems
heres the scripts i made
–Client
local player = game.Players.LocalPlayer
local char = script.Parent
local UIS = game:GetService("UserInputService")
--------------------------
--Bool Values
local flying = false
local wPressed = false
local aPressed = false
---
local sPressed = false
local dPressed = false
local debounce = false
---
local up = false
local down = false
local toggle = false
--------------------------
local event = game.ReplicatedStorage.FlightEvent
local camera = workspace.CurrentCamera
-------------------------------------
--User Input
UIS.InputBegan:Connect(function(input, chat)
if chat then return end
if input.KeyCode == Enum.KeyCode.Q and debounce == false then
debounce = true --Cooldown
if toggle == false then --Toggle flight on and off
toggle = true
flying = true
print("flight on")
event:FireServer("EnabledFlight")
else
toggle = false
flying = false
print("flight off")
event:FireServer("DisabledFlight")
end
task.wait(.05)
debounce = false
end
if input.KeyCode == Enum.KeyCode.W then
wPressed = true
print("W true")
elseif input.KeyCode == Enum.KeyCode.A then
aPressed = true
print("A trye")
elseif input.KeyCode == Enum.KeyCode.S then
sPressed = true
print("S true")
elseif input.KeyCode == Enum.KeyCode.D then
dPressed = true
print("D true")
elseif input.KeyCode == Enum.KeyCode.Space then
up = true
print("up false")
elseif input.KeyCode == Enum.KeyCode.LeftControl then
down = true
print("down true")
end
end)
UIS.InputEnded:Connect(function(input, chat)
if chat then return end
if input.KeyCode == Enum.KeyCode.W then
wPressed = false
print("W false")
elseif input.KeyCode == Enum.KeyCode.A then
aPressed = false
print("A false")
elseif input.KeyCode == Enum.KeyCode.S then
sPressed = false
print("S false")
elseif input.KeyCode == Enum.KeyCode.D then
dPressed = false
print("D false")
elseif input.KeyCode == Enum.KeyCode.Space then
up = false
print("Up false")
elseif input.KeyCode == Enum.KeyCode.LeftControl then
down = false
print("Down false")
end
end)
while task.wait() do
if flying then
--------------
--W
if wPressed == true then
local cframe = camera.CFrame
event:FireServer("W", cframe.LookVector)
elseif wPressed == false then
event:FireServer("idled")
end
--------------
--A
if aPressed == true then
local cframe = camera.CFrame
event:FireServer("A", cframe.RightVector)
elseif aPressed == false then
event:FireServer("idled")
end
--------------
--S
if sPressed == true then
local cframe = camera.CFrame
event:FireServer("S", cframe.LookVector)
elseif sPressed == false then
event:FireServer("idled")
end
--------------
--D
if dPressed == true then
local cframe = camera.CFrame
event:FireServer("D", cframe.RightVector)
elseif dPressed == false then
event:FireServer("idled")
end
--------------
--Up
if up == true then
local cframe = camera.CFrame
event:FireServer("Up", cframe.UpVector)
elseif up == false then
event:FireServer("idled")
end
--------------
--Down
if down == true then
local cframe = camera.CFrame
event:FireServer("Down", cframe.UpVector)
elseif down == false then
event:FireServer("idled")
end
end
end
–Server
local RS = game:GetService("ReplicatedStorage")
local event = RS.FlightEvent
local BV
event.OnServerEvent:Connect(function(plr, args, pos)
local char = plr.Character
local HRP = char.HumanoidRootPart
if args == "EnabledFlight" then
BV = Instance.new("BodyVelocity", HRP)
BV.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
BV.P = 2500
BV.Velocity = Vector3.new(0,0,0)
BV.Name = "Flight Controller"
elseif args == "DisabledFlight" then
BV:Destroy()
elseif args == "idled" then
BV.Velocity = Vector3.new(0,0,0)
elseif args == "W" then
print("foward")
BV.Velocity = pos * 50
elseif args == "A" then
print("left")
BV.Velocity = -pos * 50
elseif args == "S" then
print("back")
BV.Velocity = -pos * 50
elseif args == "D" then
print("right")
BV.Velocity = pos * 50
elseif args == "Up" then
print("up")
BV.Velocity = pos * 50
elseif args == "Down" then
print("down")
BV.Velocity = -pos * 50
end
end)
help would be apreciated greatly! the script is relatively simple so im not sure where the problem is exactly
thank you for your time