Why I cant move while flying I just stuck and cant move foward or backward ,can you help me and thanks
this is the local script :
local UIS = game:GetService("UserInputService")
local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
wait(1)
local IsFlying = false
local Torso = char.UpperTorso
local last = tick()
local function flight()
local bv = Instance.new("BodyVelocity")
bv.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bv.Parent = Torso
bv.Name = "FlightVelocity"
bv.Velocity = Vector3.new(0,0,0)
end
UIS.InputBegan:Connect(function(input,gpe)
if gpe then return end
if input.KeyCode == Enum.KeyCode.Space then
if (tick()-last) < 0.5 then
IsFlying = not IsFlying
if IsFlying then
flight()
else
local bv = Torso:FindFirstChild("FlightVelocity")
if bv then bv:Destroy() end
end
elseif IsFlying then
local bv = Torso:FindFirstChild("FlightVelocity")
if bv then bv.Velocity = Vector3.new(0,16,0) end
end
last = tick()
end
if input.KeyCode == Enum.KeyCode.LeftControl then
local bv = Torso:FindFirstChild("FlightVelocity")
if bv then bv.Velocity = Vector3.new(0,-16,0) end
end
end)
UIS.InputEnded:Connect(function(input,gpe)
if input.KeyCode == Enum.KeyCode.Space or input.KeyCode == Enum.KeyCode.LeftControl then
local bv = Torso:FindFirstChild("FlightVelocity")
if bv then bv.Velocity = Vector3.new(0,0,0) end
end
end)
Part.Velocity is deprecated. You could try replacing all instances of it with Part.AssemblyLinearVelocity, although I’m not sure if that would fix it. If that doesn’t work, the player’s torso might be anchored.
function fly(parent)
local bodyvelocity = Instance.new("Bodyvelocity")
bodyvelocity.MaxForce = Vector3.new(math.huge,math.huge,math.huge)
bodyvelocity.Parent = parent
local flightcontrol = {}
function flightcontrol.Flytodirection(XYORZ,val)
if XYORZ == "X" then
bodyvelocity.Velocity = Vector3.new(val,0,0)
elseif XYORZ == "Y" then
bodyvelocity.Velocity = Vector3.new(0,val,0)
elseif XYORZ == "Z" then
bodyvelocity.Velocity = Vector3.new(0,0,val)
end
end
return flightcontrol
end
However this is just the function for fly, do the input things yourself as I’m lazy to write one
example:
local bodvelocity = fly(player.HumanoidRootPart)
bodvelocity.Flytodirection("Y",10)
Would make him fly up, I like oop and ik I could shorten it but I’m lazy to do that now
Okay, for example you have X,Y,Z, these are the coordinates, so if you want the player to go up (Y) you can do
local bodvelocity = fly(player.HumanoidRootPart)
bodvelocity.Flytodirection("Y",10)
Basically, the first argument in flytodirection is a string (coordinate type) like XYZ, the 2nd argument of flytodirection is the value of the velocity for the specific coordinate type of first argument.