Advertisement
Guest User

Fly Script

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