Advertisement
wala_bingung

fly script mobile

Apr 29th, 2025
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.56 KB | Source Code | 0 0
  1. local UserInputService = game:GetService("UserInputService")
  2. local RunService = game:GetService("RunService")
  3. local Players = game:GetService("Players")
  4. local player = Players.LocalPlayer
  5. local character = player.Character or player.CharacterAdded:Wait()
  6. local humanoid = character:WaitForChild("Humanoid")
  7. local hrp = character:WaitForChild("HumanoidRootPart")
  8. local camera = game.Workspace.CurrentCamera
  9. -- Variables
  10. local isFlying = false
  11. local flySpeed = 50
  12. local velocities = {
  13.     forward = 0,
  14.     horizontal = 0,
  15.     vertical = 0
  16. }
  17. local bodyVelocity = nil
  18. -- GUI Setup
  19. local FlyGui = Instance.new("ScreenGui")
  20. FlyGui.Name = "FlyGui"
  21. FlyGui.Parent = player:WaitForChild("PlayerGui")
  22. FlyGui.ResetOnSpawn = false
  23. local Frame = Instance.new("Frame")
  24. Frame.Parent = FlyGui
  25. Frame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
  26. Frame.Position = UDim2.new(0.75, 0, 0.6, 0)
  27. Frame.Size = UDim2.new(0, 180, 0, 180)
  28. Frame.BorderSizePixel = 0
  29. local UICorner = Instance.new("UICorner")
  30. UICorner.CornerRadius = UDim.new(0.1, 0)
  31. UICorner.Parent = Frame
  32. local UIGradient = Instance.new("UIGradient")
  33. UIGradient.Color = ColorSequence.new{
  34.     ColorSequenceKeypoint.new(0, Color3.fromRGB(50, 100, 255)),
  35.     ColorSequenceKeypoint.new(1, Color3.fromRGB(100, 50, 200))
  36. }
  37. UIGradient.Parent = Frame
  38. local GridLayout = Instance.new("UIGridLayout")
  39. GridLayout.Parent = Frame
  40. GridLayout.CellSize = UDim2.new(0, 50, 0, 50)
  41. GridLayout.CellPadding = UDim2.new(0, 10, 0, 10)
  42. GridLayout.StartOrder = Enum.SortOrder.LayoutOrder
  43. -- Button Creation Function
  44. local function createButton(name, text)
  45.     local button = Instance.new("TextButton")
  46.     button.Name = name
  47.     button.Parent = Frame
  48.     button.BackgroundColor3 = Color3.fromRGB(80, 80, 120)
  49.     button.Font = Enum.Font.Gotham
  50.     button.Text = text
  51.     button.TextColor3 = Color3.fromRGB(255, 255, 255)
  52.     button.TextScaled = true
  53.     button.ZIndex = 2
  54.     local corner = UICorner:Clone()
  55.     corner.Parent = button
  56.     return button
  57. end
  58. -- Create Buttons
  59. local forwardButton = createButton("Forward", "↑")
  60. local upButton = createButton("Up", "⬆")
  61. local backwardButton = createButton("Backward", "↓")
  62. local leftButton = createButton("Left", "←")
  63. local flyButton = createButton("Fly", "Fly")
  64. local rightButton = createButton("Right", "→")
  65. local speedMinus = createButton("SpeedMinus", "-")
  66. local downButton = createButton("Down", "⬇")
  67. local speedPlus = createButton("SpeedPlus", "+")
  68. -- Connect Events
  69. flyButton.MouseButton1Click:Connect(function()
  70.     isFlying = not isFlying
  71.     flyButton.Text = isFlying and "Unfly" or "Fly"
  72. end)
  73. speedPlus.MouseButton1Click:Connect(function()
  74.     flySpeed = flySpeed + 10
  75. end)
  76. speedMinus.MouseButton1Click:Connect(function()
  77.     flySpeed = math.max(10, flySpeed - 10)
  78. end)
  79. -- Direction Buttons
  80. forwardButton.MouseButton1Down:Connect(function() velocities.forward = flySpeed end)
  81. forwardButton.MouseButton1Up:Connect(function() velocities.forward = 0 end)
  82. backwardButton.MouseButton1Down:Connect(function() velocities.forward = -flySpeed end)
  83. backwardButton.MouseButton1Up:Connect(function() velocities.forward = 0 end)
  84. leftButton.MouseButton1Down:Connect(function() velocities.horizontal = -flySpeed end)
  85. leftButton.MouseButton1Up:Connect(function() velocities.horizontal = 0 end)
  86. rightButton.MouseButton1Down:Connect(function() velocities.horizontal = flySpeed end)
  87. rightButton.MouseButton1Up:Connect(function() velocities.horizontal = 0 end)
  88. upButton.MouseButton1Down:Connect(function() velocities.vertical = flySpeed end)
  89. upButton.MouseButton1Up:Connect(function() velocities.vertical = 0 end)
  90. downButton.MouseButton1Down:Connect(function() velocities.vertical = -flySpeed end)
  91. downButton.MouseButton1Up:Connect(function() velocities.vertical = 0 end)
  92. -- Fly Logic
  93. RunService.RenderStepped:Connect(function()
  94.     if isFlying then
  95.         if not bodyVelocity then
  96.             bodyVelocity = Instance.new("BodyVelocity")
  97.             bodyVelocity.Name = "FlyVelocity"
  98.             bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  99.             bodyVelocity.Parent = hrp
  100.             humanoid.PlatformStand = true
  101.         end
  102.         local velocity = (camera.CFrame.LookVector * velocities.forward) +
  103.                          (camera.CFrame.RightVector * velocities.horizontal) +
  104.                          Vector3.new(0, velocities.vertical, 0)
  105.         bodyVelocity.Velocity = velocity
  106.     else
  107.         if bodyVelocity then
  108.             bodyVelocity:Destroy()
  109.             bodyVelocity = nil
  110.             humanoid.PlatformStand = false
  111.         end
  112.     end
  113. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement