local Players = game:GetService("Players") local UIS = game:GetService("UserInputService") local RunService = game:GetService("RunService") local player = Players.LocalPlayer local camera = workspace.CurrentCamera local FLY_KEY = Enum.KeyCode.F local SPEED = 60 local flying = false local upHeld, downHeld = false, false local bv, bg, conn -- Movement vector for both keyboard (WASD) and mobile joystick local controls = require(player:WaitForChild("PlayerScripts"):WaitForChild("PlayerModule")):GetControls() --------------------------------------------------------------------- -- GUI --------------------------------------------------------------------- local gui = Instance.new("ScreenGui") gui.Name = "FlyGui" gui.ResetOnSpawn = false gui.Parent = player:WaitForChild("PlayerGui") local function makeButton(text, size, pos) local b = Instance.new("TextButton") b.Size = size b.Position = pos b.Text = text b.TextScaled = true b.Font = Enum.Font.GothamBold b.TextColor3 = Color3.new(1, 1, 1) b.BackgroundColor3 = Color3.fromRGB(40, 40, 40) b.BackgroundTransparency = 0.25 b.AutoButtonColor = true b.Parent = gui local corner = Instance.new("UICorner") corner.CornerRadius = UDim.new(0, 12) corner.Parent = b return b end local toggleBtn = makeButton("FLY: OFF", UDim2.fromOffset(120, 50), UDim2.new(1, -140, 0.5, -90)) local upBtn = makeButton("▲", UDim2.fromOffset(70, 70), UDim2.new(1, -90, 0.5, -30)) local downBtn = makeButton("▼", UDim2.fromOffset(70, 70), UDim2.new(1, -90, 0.5, 50)) upBtn.Visible = false downBtn.Visible = false local function updateGui() toggleBtn.Text = flying and "FLY: ON" or "FLY: OFF" toggleBtn.BackgroundColor3 = flying and Color3.fromRGB(30, 140, 60) or Color3.fromRGB(40, 40, 40) upBtn.Visible = flying downBtn.Visible = flying end -- Hold detection (touch + mouse) local function bindHold(button, setter) button.InputBegan:Connect(function(input) if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then setter(true) end end) button.InputEnded:Connect(function(input) if input.UserInputType == Enum.UserInputType.Touch or input.UserInputType == Enum.UserInputType.MouseButton1 then setter(false) end end) end bindHold(upBtn, function(v) upHeld = v end) bindHold(downBtn, function(v) downHeld = v end) --------------------------------------------------------------------- -- Fly logic --------------------------------------------------------------------- local function stopFly() flying = false upHeld, downHeld = false, false if conn then conn:Disconnect() conn = nil end if bv then bv:Destroy() bv = nil end if bg then bg:Destroy() bg = nil end local char = player.Character local hum = char and char:FindFirstChildOfClass("Humanoid") if hum then hum.PlatformStand = false end updateGui() end local function startFly() local char = player.Character local hrp = char and char:FindFirstChild("HumanoidRootPart") local hum = char and char:FindFirstChildOfClass("Humanoid") if not hrp or not hum then return end flying = true hum.PlatformStand = true bv = Instance.new("BodyVelocity") bv.MaxForce = Vector3.new(1e9, 1e9, 1e9) bv.Velocity = Vector3.zero bv.Parent = hrp bg = Instance.new("BodyGyro") bg.MaxTorque = Vector3.new(1e9, 1e9, 1e9) bg.P = 1e4 bg.CFrame = hrp.CFrame bg.Parent = hrp conn = RunService.RenderStepped:Connect(function() local cf = camera.CFrame local mv = controls:GetMoveVector() -- x: right/left, z: back/forward local dir = cf.RightVector * mv.X + cf.LookVector * -mv.Z if upHeld or UIS:IsKeyDown(Enum.KeyCode.Space) then dir += Vector3.yAxis end if downHeld or UIS:IsKeyDown(Enum.KeyCode.LeftControl) then dir -= Vector3.yAxis end bv.Velocity = dir.Magnitude > 0 and dir.Unit * SPEED or Vector3.zero bg.CFrame = cf end) updateGui() end local function toggleFly() if flying then stopFly() else startFly() end end toggleBtn.Activated:Connect(toggleFly) UIS.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.KeyCode == FLY_KEY then toggleFly() end end) player.CharacterAdded:Connect(stopFly) updateGui()