JohnLennonPlays

fly script, script builder

Feb 13th, 2021 (edited)
1,019
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.57 KB | None | 0 0
  1. --[[
  2.     This script is for synapse x/non luau supported executors
  3. --]]
  4. -- services
  5. local players = game:GetService("Players")
  6. local runService = game:GetService("RunService")
  7. local inputService = game:GetService("UserInputService")
  8. -- objects
  9. local player = players.LocalPlayer
  10. local character = player.Character or player.CharacterAdded:Wait()
  11. local humanoid, rootPart
  12. local camera = workspace.CurrentCamera
  13. -- variables
  14. local rootPartCFrame
  15. local flyObj = {
  16.     enabled = false,
  17.     keyInput = Enum.KeyCode.F1,
  18.     flySpeed = .9,
  19.     qeFly = false,
  20.  
  21.     _navigation = {
  22.         upward = false,
  23.         downward = false,
  24.         forward = false,
  25.         backward = false,
  26.         rightward = false,
  27.         leftward = false,
  28.     }
  29. }
  30. -- functions
  31. local function onCharacterAdded(newCharacter)
  32.     character = newCharacter
  33.     humanoid, rootPart = character:FindFirstChildWhichIsA("Humanoid"), character:WaitForChild("HumanoidRootPart")
  34. end
  35. -- main
  36. onCharacterAdded(character)
  37. player.CharacterAdded:Connect(onCharacterAdded)
  38.  
  39. inputService.InputBegan:Connect(function(input, gameProcessedEvent)
  40.     if input.UserInputType == Enum.UserInputType.Keyboard and not (inputService:GetFocusedTextBox() and gameProcessedEvent) then
  41.         if input.KeyCode == flyObj.keyInput then
  42.             flyObj.enabled = not flyObj.enabled
  43.             rootPartCFrame = rootPart.CFrame
  44.         end
  45.     end
  46. end)
  47.  
  48. runService.RenderStepped:Connect(function()
  49.     if not inputService:GetFocusedTextBox() and flyObj.enabled then
  50.         flyObj._navigation.upward = (flyObj.qeFly and inputService:IsKeyDown(Enum.KeyCode.Q))
  51.         flyObj._navigation.downward = (flyObj.qeFly and inputService:IsKeyDown(Enum.KeyCode.E))
  52.         flyObj._navigation.forward = inputService:IsKeyDown(Enum.KeyCode.W)
  53.         flyObj._navigation.backward = inputService:IsKeyDown(Enum.KeyCode.S)
  54.         flyObj._navigation.leftward = inputService:IsKeyDown(Enum.KeyCode.A)
  55.         flyObj._navigation.rightward = inputService:IsKeyDown(Enum.KeyCode.D)
  56.     end
  57. end)
  58.  
  59. runService.Heartbeat:Connect(function(deltaTime)
  60.     if flyObj.enabled and (humanoid and rootPart) then
  61.         for _, animObj in ipairs(humanoid:GetPlayingAnimationTracks()) do animObj:Stop(0) end
  62.         local cameraOrientation = CFrame.fromOrientation(camera.CFrame:ToOrientation())
  63.         local calcFront, calcRight, calcTop = (cameraOrientation.LookVector), (cameraOrientation.RightVector), (cameraOrientation.UpVector)
  64.         local pressedDirection do
  65.             pressedDirection = Vector3.zero
  66.  
  67.             for name, pressed in pairs(flyObj._navigation) do
  68.                 if not pressed then
  69.                     pressedDirection = pressedDirection + Vector3.zero
  70.                 else
  71.                     if name == "rightward" then
  72.                         pressedDirection = pressedDirection + calcRight
  73.                     elseif name == "upward" then
  74.                         pressedDirection = pressedDirection + calcTop
  75.                     elseif name == "forward" then
  76.                         pressedDirection = pressedDirection + calcFront
  77.                     elseif name == "leftward" then
  78.                         pressedDirection = pressedDirection - calcRight
  79.                     elseif name == "downward" then
  80.                         pressedDirection = pressedDirection - calcTop
  81.                     elseif name == "backward" then
  82.                         pressedDirection = pressedDirection - calcFront
  83.                     end
  84.                 end
  85.             end
  86.             pressedDirection = pressedDirection * ((flyObj.flySpeed / 0.0305) * deltaTime)
  87.         end
  88.         local difference = (rootPartCFrame.Position - rootPart.Position)
  89.  
  90.         rootPart.Anchored = false
  91.         humanoid:ChangeState(Enum.HumanoidStateType.Climbing)
  92.         character:TranslateBy(pressedDirection)
  93.         rootPart.CFrame = ((CFrame.identity + (rootPart.Position + difference)) * cameraOrientation)
  94.         rootPartCFrame = rootPart.CFrame
  95.         rootPart.AssemblyLinearVelocity, rootPart.AssemblyAngularVelocity = Vector3.zero, Vector3.zero
  96.     end
  97. end)
Advertisement
Add Comment
Please, Sign In to add comment