Advertisement
the_unknownz

Fly Script

Jun 16th, 2018
32,612
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.58 KB | None | 0 0
  1. wait();
  2.  
  3. local MaxFlySpeed = 2 -- change this as needed
  4.  
  5. local UIS = game:GetService("UserInputService")
  6. local LocalPlayer = game:GetService("Players").LocalPlayer
  7. local Torso = (LocalPlayer.Character and LocalPlayer.Character:WaitForChild("Torso"))
  8. local Mouse = LocalPlayer:GetMouse()
  9. local Tool = Instance.new("Tool")
  10. Tool.RequiresHandle = false
  11. Tool.Name = "Fly tool"
  12.  
  13. assert(Torso.ClassName == "Part", "Yikes! Torso is not a part.")
  14.  
  15. local ToolUtils do
  16.     ToolUtils = {
  17.         --// Setup Vars
  18.         Enabled = false,
  19.         WindowFocused = true,
  20.  
  21.         Keys = {},        
  22.         InternalVars = {
  23.             FlyForward = 0,
  24.             FlyBackward = 0
  25.         }      
  26.     }
  27. end
  28.  
  29. local ToolEvents do
  30.     Tool.Equipped:connect(function(Mouse)
  31.         ToolUtils.Enabled = true
  32.         Torso.Anchored = true
  33.     end)
  34.     Tool.Unequipped:connect(function(...)
  35.         ToolUtils.Enabled = false
  36.         Torso.Anchored = false
  37.     end)
  38.     UIS.InputBegan:connect(function(input, processedEvent)
  39.         ToolUtils.Keys[input.KeyCode] = true
  40.     end)
  41.     UIS.InputEnded:connect(function(input, processedEvent)
  42.         ToolUtils.Keys[input.KeyCode] = nil
  43.     end)
  44.     UIS.WindowFocusReleased:connect(function()
  45.         ToolUtils.WindowFocused = false
  46.     end)
  47.     UIS.WindowFocused:connect(function()
  48.         ToolUtils.WindowFocused = true
  49.     end)
  50. end
  51.  
  52. --// Main Event
  53. game:GetService("RunService").RenderStepped:connect(function(...)
  54.     if ToolUtils.WindowFocused and ToolUtils.Enabled then
  55.         if ToolUtils.Keys[Enum.KeyCode.W] then
  56.             if ToolUtils.InternalVars.FlyForward < MaxFlySpeed then
  57.                 ToolUtils.InternalVars.FlyForward = ToolUtils.InternalVars.FlyForward + 0.1
  58.             end
  59.         else
  60.             ToolUtils.InternalVars.FlyForward = ToolUtils.InternalVars.FlyForward * 0.9
  61.         end
  62.         if ToolUtils.Keys[Enum.KeyCode.S] then
  63.             if ToolUtils.InternalVars.FlyBackward < MaxFlySpeed then
  64.                 ToolUtils.InternalVars.FlyBackward = ToolUtils.InternalVars.FlyBackward + 0.1
  65.             end
  66.         else
  67.             ToolUtils.InternalVars.FlyBackward = ToolUtils.InternalVars.FlyBackward * 0.9          
  68.         end
  69.        
  70.         local Camera = workspace.CurrentCamera
  71.         Torso.CFrame = Torso.CFrame:lerp(
  72.             CFrame.new(Torso.Position, Camera.CFrame.p)
  73.                * CFrame.Angles(0, math.rad(180), 0)
  74.                * CFrame.new(0, 0, -(ToolUtils.InternalVars.FlyForward - ToolUtils.InternalVars.FlyBackward))
  75.                * CFrame.Angles(-(math.rad(10 * (ToolUtils.InternalVars.FlyForward / MaxFlySpeed)) - math.rad(10 * (ToolUtils.InternalVars.FlyBackward / MaxFlySpeed))), 0, 0)
  76.         , 0.9)
  77.     end
  78. end)
  79.  
  80. Tool.Parent = LocalPlayer:findFirstChild("Backpack") or Instance.new("Backpack", LocalPlayer)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement