Advertisement
YESSIR455bb

FLY

Apr 29th, 2025
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.74 KB | None | 0 0
  1. local UserInputService = game:GetService("UserInputService")
  2. local LocalPlayer = game.Players.LocalPlayer
  3. local flying = false
  4. local flightSpeed = 50
  5. local bodyVelocity
  6. local bodyGyro
  7. local doublePressTime = 0.5
  8. local lastPressTime = 0
  9.  
  10. -- Change character state to Physics (stops falling animation)
  11. local function setIdleState()
  12. local humanoid = LocalPlayer.Character and LocalPlayer.Character:FindFirstChildWhichIsA("Humanoid")
  13. if humanoid and humanoid:GetState() ~= Enum.HumanoidStateType.Seated then
  14. humanoid:ChangeState(Enum.HumanoidStateType.Physics)
  15. end
  16. end
  17.  
  18. -- Start flying
  19. local function startFlying()
  20. if flying then return end
  21. flying = true
  22.  
  23. local character = LocalPlayer.Character
  24. local rootPart = character and character:FindFirstChild("HumanoidRootPart")
  25. if not rootPart then return end
  26.  
  27. bodyVelocity = Instance.new("BodyVelocity")
  28. bodyVelocity.MaxForce = Vector3.new(1e5, 1e5, 1e5)
  29. bodyVelocity.Velocity = Vector3.new(0, 0, 0)
  30. bodyVelocity.Parent = rootPart
  31.  
  32. bodyGyro = Instance.new("BodyGyro")
  33. bodyGyro.MaxTorque = Vector3.new(1e5, 1e5, 1e5)
  34. bodyGyro.P = 1e4
  35. bodyGyro.CFrame = rootPart.CFrame
  36. bodyGyro.Parent = rootPart
  37.  
  38. while flying and character.Parent do
  39. setIdleState()
  40. local moveDirection = Vector3.new()
  41. if UserInputService:IsKeyDown(Enum.KeyCode.W) then
  42. moveDirection += workspace.CurrentCamera.CFrame.LookVector
  43. end
  44. if UserInputService:IsKeyDown(Enum.KeyCode.S) then
  45. moveDirection -= workspace.CurrentCamera.CFrame.LookVector
  46. end
  47. if UserInputService:IsKeyDown(Enum.KeyCode.A) then
  48. moveDirection -= workspace.CurrentCamera.CFrame.RightVector
  49. end
  50. if UserInputService:IsKeyDown(Enum.KeyCode.D) then
  51. moveDirection += workspace.CurrentCamera.CFrame.RightVector
  52. end
  53. if UserInputService:IsKeyDown(Enum.KeyCode.Space) then
  54. moveDirection += Vector3.new(0, 1, 0)
  55. end
  56. if UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then
  57. moveDirection -= Vector3.new(0, 1, 0)
  58. end
  59.  
  60. if moveDirection.Magnitude > 0 then
  61. moveDirection = moveDirection.Unit
  62. bodyVelocity.Velocity = moveDirection * flightSpeed
  63. else
  64. bodyVelocity.Velocity = Vector3.zero
  65. end
  66.  
  67. bodyGyro.CFrame = workspace.CurrentCamera.CFrame
  68. task.wait()
  69. end
  70. end
  71.  
  72. -- Stop flying
  73. local function stopFlying()
  74. flying = false
  75. if bodyVelocity then bodyVelocity:Destroy() end
  76. if bodyGyro then bodyGyro:Destroy() end
  77. end
  78.  
  79. -- Double space to toggle flight
  80. UserInputService.InputBegan:Connect(function(input, processed)
  81. if processed then return end
  82. if input.KeyCode == Enum.KeyCode.Space then
  83. local now = tick()
  84. if now - lastPressTime < doublePressTime then
  85. if flying then
  86. stopFlying()
  87. else
  88. startFlying()
  89. end
  90. end
  91. lastPressTime = now
  92. end
  93. end)
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement