Advertisement
Guest User

Flying Script

a guest
Jun 2nd, 2024
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.49 KB | None | 0 0
  1. _G.Speed = 50
  2. _G.Key = Enum.KeyCode.X
  3.  
  4. local UIS = game:GetService("UserInputService")
  5. local OnRender = game:GetService("RunService").RenderStepped
  6.  
  7. local Player = game:GetService("Players").LocalPlayer
  8. local Character = Player.Character or Player.CharacterAdded:Wait()
  9.  
  10. local Camera = workspace.CurrentCamera
  11. local Root = Character:WaitForChild("HumanoidRootPart")
  12.  
  13. local C1, C2, C3;
  14. local UntitledHood = {Flying = false, Forward = false, Backward = false, Left = false, Right = false}
  15. C1 = UIS.InputBegan:Connect(function(Input)
  16.     if Input.UserInputType == Enum.UserInputType.Keyboard then
  17.         if Input.KeyCode == _G.Key then
  18.             UntitledHood.Flying = not UntitledHood.Flying
  19.             Root.Anchored = UntitledHood.Flying
  20.         elseif Input.KeyCode == Enum.KeyCode.W then
  21.             UntitledHood.Forward = true
  22.         elseif Input.KeyCode == Enum.KeyCode.S then
  23.             UntitledHood.Backward = true
  24.         elseif Input.KeyCode == Enum.KeyCode.A then
  25.             UntitledHood.Left = true
  26.         elseif Input.KeyCode == Enum.KeyCode.D then
  27.             UntitledHood.Right = true
  28.         end
  29.     end
  30. end)
  31.  
  32. C2 = UIS.InputEnded:Connect(function(Input)
  33.     if Input.UserInputType == Enum.UserInputType.Keyboard then
  34.         if Input.KeyCode == Enum.KeyCode.W then
  35.             UntitledHood.Forward = false
  36.         elseif Input.KeyCode == Enum.KeyCode.S then
  37.             UntitledHood.Backward = false
  38.         elseif Input.KeyCode == Enum.KeyCode.A then
  39.             UntitledHood.Left = false
  40.         elseif Input.KeyCode == Enum.KeyCode.D then
  41.             UntitledHood.Right = false
  42.         end
  43.     end
  44. end)
  45.  
  46. C3 = Camera:GetPropertyChangedSignal("CFrame"):Connect(function()
  47.     if UntitledHood.Flying then
  48.         Root.CFrame = CFrame.new(Root.CFrame.Position, Root.CFrame.Position + Camera.CFrame.LookVector)
  49.     end
  50. end)
  51.  
  52. while true do
  53.     local Delta = OnRender:Wait()
  54.     if UntitledHood.Flying then
  55.         if UntitledHood.Forward then
  56.             Root.CFrame = Root.CFrame + (Camera.CFrame.LookVector * (Delta * _G.Speed))
  57.         end
  58.         if UntitledHood.Backward then
  59.             Root.CFrame = Root.CFrame + (-Camera.CFrame.LookVector * (Delta * _G.Speed))
  60.         end
  61.         if UntitledHood.Left then
  62.             Root.CFrame = Root.CFrame + (-Camera.CFrame.RightVector * (Delta * _G.Speed))
  63.         end
  64.         if UntitledHood.Right then
  65.             Root.CFrame = Root.CFrame + (Camera.CFrame.RightVector * (Delta * _G.Speed))
  66.         end
  67.     end
  68. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement