Poglo

Roblox simple script fly

Jun 26th, 2022 (edited)
930
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.81 KB | None
  1. --[[Press "p" to toggle fly]]
  2. repeat wait()
  3.    until game:service'Players'.LocalPlayer and game:service'Players'.LocalPlayer.Character and game:service'Players'.LocalPlayer.Character:findFirstChild("HumanoidRootPart") and game:service'Players'.LocalPlayer.Character:findFirstChild("Humanoid")
  4. local mouse = game:service'Players'.LocalPlayer:GetMouse()
  5. repeat wait() until mouse
  6. local plr = game:service'Players'.LocalPlayer
  7. local HumanoidRootPart = plr.Character.HumanoidRootPart
  8. local flying = true
  9. local deb = true
  10. local ctrl = {f = 0, b = 0, l = 0, r = 0}
  11. local lastctrl = {f = 0, b = 0, l = 0, r = 0}
  12. local maxspeed = 50
  13. local speed = 0
  14.  
  15. function Fly()
  16. local bg = Instance.new("BodyGyro", HumanoidRootPart)
  17. bg.P = 9e4
  18. bg.maxTorque = Vector3.new(9e9, 9e9, 9e9)
  19. bg.cframe = HumanoidRootPart.CFrame
  20. local bv = Instance.new("BodyVelocity", HumanoidRootPart)
  21. bv.velocity = Vector3.new(0,0.1,0)
  22. bv.maxForce = Vector3.new(9e9, 9e9, 9e9)
  23. repeat wait()
  24. plr.Character.Humanoid.PlatformStand = true
  25. if ctrl.l + ctrl.r ~= 0 or ctrl.f + ctrl.b ~= 0 then
  26. speed = speed+.5+(speed/maxspeed)
  27. if speed > maxspeed then
  28. speed = maxspeed
  29. end
  30. elseif not (ctrl.l + ctrl.r ~= 0 or ctrl.f + ctrl.b ~= 0) and speed ~= 0 then
  31. speed = speed-1
  32. if speed < 0 then
  33. speed = 0
  34. end
  35. end
  36. if (ctrl.l + ctrl.r) ~= 0 or (ctrl.f + ctrl.b) ~= 0 then
  37. bv.velocity = ((workspace.CurrentCamera.CoordinateFrame.lookVector * (ctrl.f+ctrl.b)) + ((workspace.CurrentCamera.CoordinateFrame * CFrame.new(ctrl.l+ctrl.r,(ctrl.f+ctrl.b)*.2,0).p) - workspace.CurrentCamera.CoordinateFrame.p))*speed
  38. lastctrl = {f = ctrl.f, b = ctrl.b, l = ctrl.l, r = ctrl.r}
  39. elseif (ctrl.l + ctrl.r) == 0 and (ctrl.f + ctrl.b) == 0 and speed ~= 0 then
  40. bv.velocity = ((workspace.CurrentCamera.CoordinateFrame.lookVector * (lastctrl.f+lastctrl.b)) + ((workspace.CurrentCamera.CoordinateFrame * CFrame.new(lastctrl.l+lastctrl.r,(lastctrl.f+lastctrl.b)*.2,0).p) - workspace.CurrentCamera.CoordinateFrame.p))*speed
  41. else
  42. bv.velocity = Vector3.new(0,0.1,0)
  43. end
  44. bg.cframe = workspace.CurrentCamera.CoordinateFrame * CFrame.Angles(-math.rad((ctrl.f+ctrl.b)*50*speed/maxspeed),0,0)
  45. until not flying
  46. ctrl = {f = 0, b = 0, l = 0, r = 0}
  47. lastctrl = {f = 0, b = 0, l = 0, r = 0}
  48. speed = 0
  49. bg:Destroy()
  50. bv:Destroy()
  51. plr.Character.Humanoid.PlatformStand = false
  52. end
  53. mouse.KeyDown:connect(function(key)
  54. if key:lower() == "p" then
  55. if flying then flying = false
  56. else
  57. flying = true
  58. Fly()
  59. end
  60. elseif key:lower() == "w" then
  61. ctrl.f = 1
  62. elseif key:lower() == "s" then
  63. ctrl.b = -1
  64. elseif key:lower() == "a" then
  65. ctrl.l = -1
  66. elseif key:lower() == "d" then
  67. ctrl.r = 1
  68. end
  69. end)
  70. mouse.KeyUp:connect(function(key)
  71. if key:lower() == "w" then
  72. ctrl.f = 0
  73. elseif key:lower() == "s" then
  74. ctrl.b = 0
  75. elseif key:lower() == "a" then
  76. ctrl.l = 0
  77. elseif key:lower() == "d" then
  78. ctrl.r = 0
  79. end
  80. end)
  81. Fly()
RAW Paste Data Copied