I Need Help With My Flight System

Hello again, I’m working with a fly project for my DBZ game, it works perfectly but, I found that for mobile it doesn’t have controls to fly, so I realized that many players were complaining that on mobile they can’t fly.

This is Script for Fly System:

wait(3)
print(‘fly’)
local player = game.Players.LocalPlayer
local pchar = player.Character
local char = player.Character
local hum = char.Humanoid
local root = pchar.HumanoidRootPart
local mouse = player:GetMouse()
local cam = workspace.CurrentCamera

local rad = math.rad

local keysDown = {}
local flySpeed = 0
local MAX_FLY_SPEED = 170

local canFly = true
local flyToggled = false

local forward, side = 0, 0
local lastForward, lastSide = 0, 0
fly stance R6 - Roblox
local stn = hum:LoadAnimation(script.stance)
local fow = hum:LoadAnimation(script.forw)
local bk = hum:LoadAnimation(script.back)
local ri = hum:LoadAnimation(script.right)
local le = hum:LoadAnimation(script.left)

local floatBP = Instance.new(“BodyPosition”)
floatBP.maxForce = Vector3.new(0, math.huge, 0)
local flyBV = Instance.new(“BodyVelocity”)
flyBV.maxForce = Vector3.new(9e9, 9e9, 9e9)
local turnBG = Instance.new(“BodyGyro”)
turnBG.maxTorque = Vector3.new(math.huge, math.huge, math.huge)

mouse.KeyDown:connect(function(key)
keysDown[key] = true

    if key == "f" then
            flyToggled = not flyToggled

    if not flyToggled then	
            stanceToggle = "Normal"
            floatBP.Parent = nil
            flyBV.Parent = nil
            turnBG.Parent = nil
            root.Velocity = Vector3.new()
            pchar.Humanoid.PlatformStand = false
    end

end

end)
mouse.KeyUp:connect(function(key)
keysDown[key] = nil
stn:Play()
fow:Stop()
ri:Stop()
le:Stop()
bk:Stop()
if not flyToggled then
stn:Stop()
fow:Stop()
ri:Stop()
le:Stop()
bk:Stop()
end

end)

local function updateFly()

    if not flyToggled then return end

    lastForward = forward
    lastSide = side

    forward = 0
    side = 0

    if keysDown.w then
            forward = forward + 1

le:Stop()
stn:Stop()
ri:stop()
bk:Stop()
fow:Play()
end
if keysDown.s then
forward = forward - 1
fow:Stop()
stn:Stop()
le:Stop()
ri:Stop()
bk:Play()
end
if keysDown.a then
side = side - 1
ri:Stop()
fow:Stop()
stn:Stop()
bk:Stop()
le:Play()
end
if keysDown.d then
side = side + 1
fow:Stop()
bk:Stop()
le:Stop()
stn:Stop()
ri:Play()
end

    canFly = (forward ~= 0 or side ~= 0)

    if canFly then
            stanceToggle = "Floating"
            turnBG.Parent = root
            floatBP.Parent = nil
            flyBV.Parent = root


            flySpeed = flySpeed + 1 + (flySpeed / MAX_FLY_SPEED)
            if flySpeed > MAX_FLY_SPEED then flySpeed = MAX_FLY_SPEED end
    else
            floatBP.position = root.Position
            floatBP.Parent = root

            flySpeed = flySpeed - 1
            if flySpeed < 0 then flySpeed = 0 end
    end

    local camCF = cam.CoordinateFrame
    local in_forward = canFly and forward or lastForward
    local in_side = canFly and side or lastSide

    flyBV.velocity = ((camCF.lookVector * in_forward) + (camCF * CFrame.new(in_side,in_forward * 0.2, 0).p) - camCF.p) * flySpeed

    turnBG.cframe = camCF * CFrame.Angles(-rad(forward * (flySpeed / MAX_FLY_SPEED)), 0,0)

end

mouse.KeyDown:connect(function()

end)
game:service’RunService’.RenderStepped:connect(function()
if flyToggled then
pchar.Humanoid.PlatformStand = true
updateFly()
end

end)

What function do I add to my fly system, so that I can fly on my cell phone too? Any ideas or opinions? Thanks. :slightly_smiling_face:

Have you tried using ContextActionService? Also, why are you using Mouse when it’s better to use UserInputService?

No more than you suggest I can do? I’m a newcomer to this command.

Using ContextActionService, you can bind functions, like, say, directional flying functions, to buttons that only appear on mobile. Also, Mouse has been succeeded by UserInputService, which is more simple to use.

Oh cool, how do I add this command? Would I have to create a bunch of buttons on my cell phone screen?

Feel free to read this to learn more.

Ok I will try to add this function.