Advertisement
TheInfamousExploiter

Roblox Fly Script (works June 2023!)

Jun 19th, 2023 (edited)
9,104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.01 KB | None | 0 0
  1. -- to fly, hit CTRL + F  
  2.  
  3. local flyspeed = 200
  4. local flying = false
  5. local maxdistance = 100000000000000 --using math.huge makes this script wonky
  6. local uiservice = game.UserInputService
  7. local lplr = game.Players.LocalPlayer
  8. local mouse = lplr:GetMouse()
  9. local function GetVelocity(pos1,pos2,StudsPerSecond)
  10. local distance = (pos2 - pos1)
  11. local mag = distance.Magnitude
  12. return (distance/mag)*StudsPerSecond
  13. end
  14. local function getkey(keycode)
  15. local key = tostring(keycode):lower()
  16. local findcode, a = key:find("keycode.")
  17. return key:sub(a+1)
  18. end
  19. local keys = {}
  20. game.RunService.Heartbeat:connect(function()
  21. pcall(function()
  22. local hrp = lplr.Character.Humanoid.RootPart
  23. local frontoffset = CFrame.new() + Vector3.new(0,0,-maxdistance)
  24. local backoffset = CFrame.new() + Vector3.new(0,0,maxdistance)
  25. local leftoffset = CFrame.new() + Vector3.new(-maxdistance,0,0)
  26. local rightoffset = CFrame.new() + Vector3.new(maxdistance,0,0)
  27. local upoffset = CFrame.new() + Vector3.new(0,maxdistance,0)
  28. local downoffset = CFrame.new() + Vector3.new(0,-maxdistance,0)
  29. local velocity = Vector3.new()
  30.     if flying then
  31.     if keys.w_active then
  32.         velocity = velocity + GetVelocity(hrp.Position,(hrp.CFrame*frontoffset).Position,flyspeed)
  33.     end
  34.     if keys.s_active then
  35.         velocity = velocity + GetVelocity(hrp.Position,(hrp.CFrame*backoffset).Position,flyspeed)
  36.     end
  37.     if keys.a_active then
  38.         velocity = velocity + GetVelocity(hrp.Position,(hrp.CFrame*leftoffset).Position,flyspeed)
  39.     end
  40.     if keys.d_active then
  41.         velocity = velocity + GetVelocity(hrp.Position,(hrp.CFrame*rightoffset).Position,flyspeed)
  42.     end
  43.     if keys.e_active then
  44.         velocity = velocity + GetVelocity(hrp.Position,(CFrame.new(hrp.Position)*upoffset).Position,flyspeed)
  45.     end
  46.     if keys.q_active then
  47.         velocity = velocity + GetVelocity(hrp.Position,(CFrame.new(hrp.Position)*downoffset).Position,flyspeed)
  48.     end
  49.     hrp.Velocity = velocity
  50.      hrp.CFrame = CFrame.new(hrp.Position, (workspace.Camera.CFrame*(CFrame.new()+Vector3.new(0,0,-maxdistance))).Position)
  51.     end
  52.     if flying and not keys.w_active and not keys.a_active and not keys.s_active and not keys.d_active and not keys.q_active and not keys.e_active then
  53.         hrp.Anchored = true
  54.     else
  55.         hrp.Anchored = false
  56.     end
  57. end)
  58. end)
  59. uiservice.InputBegan:connect(function(key,processed)
  60. if processed then return end
  61.     if key.KeyCode == Enum.KeyCode.F and game.UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then
  62.         flying = not flying
  63.         if flying then
  64.             uiservice.MouseBehavior = Enum.MouseBehavior.LockCenter
  65.             lplr.Character.Humanoid.CameraOffset = Vector3.new(2,0,0)
  66.         else
  67.             uiservice.MouseBehavior = Enum.MouseBehavior.Default
  68.             lplr.Character.Humanoid.CameraOffset = Vector3.new(0,0,0)
  69.         end
  70.     end
  71.     keys[getkey(key.KeyCode).."_active"] = true
  72. end)
  73. uiservice.InputEnded:connect(function(key)
  74.     keys[getkey(key.KeyCode).."_active"] = false
  75. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement