UsernameRTX

Phantom Forces Easy Fly

Jul 19th, 2021
4,651
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local Players = game:GetService("Players")
  2. local UserInputService = game:GetService("UserInputService")
  3. local RunService = game:GetService("RunService")
  4.  
  5. local CurrentCamera = workspace.CurrentCamera
  6.  
  7. local LocalPlayer = Players.LocalPlayer
  8.  
  9. local Boolean = false
  10. local Speed = 50
  11. local MovementTable = {
  12.     0,
  13.     0,
  14.     0,
  15.     0,
  16.     0,
  17.     0
  18. }
  19. local KeyCodeTable = {
  20.     [Enum.KeyCode.W] = 1,
  21.     [Enum.KeyCode.A] = 2,
  22.     [Enum.KeyCode.S] = 3,
  23.     [Enum.KeyCode.D] = 4,
  24.     [Enum.KeyCode.LeftControl] = 5,
  25.     [Enum.KeyCode.Space] = 6
  26. }
  27.  
  28. UserInputService.InputBegan:Connect(function(Input, ...)
  29.     if Input.KeyCode == Enum.KeyCode.F then
  30.         if Boolean then
  31.             Boolean = false
  32.         else
  33.             Boolean = true
  34.         end
  35.     elseif Input.KeyCode == Enum.KeyCode.LeftShift then
  36.         Speed = 100
  37.     elseif KeyCodeTable[Input.KeyCode] then
  38.         MovementTable[KeyCodeTable[Input.KeyCode]] = 1
  39.     end
  40. end)
  41.  
  42. UserInputService.InputEnded:Connect(function(Input, ...)
  43.     if Input.KeyCode == Enum.KeyCode.LeftShift then
  44.         Speed = 50
  45.     elseif KeyCodeTable[Input.KeyCode] then
  46.         MovementTable[KeyCodeTable[Input.KeyCode]] = 0
  47.     end
  48. end)
  49.  
  50. local GetMass = function(Model)
  51.     local Mass = 0
  52.     for _, Value in pairs(Model:GetDescendants()) do
  53.         if Value:IsA("BasePart") then
  54.             Mass = Mass + Value:GetMass()
  55.         end
  56.     end
  57.     return Mass * workspace.Gravity
  58. end
  59.  
  60. RunService.RenderStepped:Connect(function(...)
  61.     local Character = LocalPlayer.Character
  62.     if Character then
  63.         local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
  64.         local Mass = GetMass(Character)
  65.         if HumanoidRootPart then
  66.             local BodyVelocity = HumanoidRootPart:FindFirstChildOfClass("BodyVelocity")
  67.             if BodyVelocity then
  68.                 if Boolean then
  69.                     BodyVelocity.MaxForce = Vector3.new(Mass * Speed, Mass * Speed, Mass * Speed)
  70.                     BodyVelocity.Velocity = CurrentCamera.CFrame.LookVector * Speed * (MovementTable[1] - MovementTable[3]) + CurrentCamera.CFrame.RightVector * Speed * (MovementTable[4] - MovementTable[2]) + CurrentCamera.CFrame.UpVector * Speed * (MovementTable[6] - MovementTable[5])
  71.                 else
  72.                     BodyVelocity.MaxForce = Vector3.new(0, 0, 0)
  73.                     BodyVelocity.Velocity = Vector3.new(0, 2, 0)
  74.                 end
  75.             end
  76.         end
  77.     end
  78. end)
RAW Paste Data