Advertisement
VenoxComeback

Auto

Apr 15th, 2025
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 KB | None | 0 0
  1. local flySpeed = 2
  2. local uis = game:GetService("UserInputService")
  3. local player = game.Players.LocalPlayer
  4. local camera = workspace.CurrentCamera
  5.  
  6. local flying = false
  7. local moveDirection = Vector3.zero
  8.  
  9. local keysDown = {
  10. W = false,
  11. A = false,
  12. S = false,
  13. D = false,
  14. Space = false,
  15. LeftShift = false
  16. }
  17.  
  18. -- Toggle flight
  19. local function toggleFlight()
  20. flying = not flying
  21. local char = player.Character
  22. if char and char:FindFirstChild("Humanoid") then
  23. char.Humanoid.PlatformStand = flying
  24. end
  25. end
  26.  
  27. -- Input handlers
  28. uis.InputBegan:Connect(function(input, processed)
  29. if processed then return end
  30. if input.UserInputType == Enum.UserInputType.Keyboard then
  31. local key = input.KeyCode.Name
  32.  
  33. -- Handle toggle
  34. if key == "T" then
  35. toggleFlight()
  36. end
  37.  
  38. if keysDown[key] ~= nil then
  39. keysDown[key] = true
  40. end
  41. end
  42. end)
  43.  
  44. uis.InputEnded:Connect(function(input)
  45. if input.UserInputType == Enum.UserInputType.Keyboard then
  46. local key = input.KeyCode.Name
  47. if keysDown[key] ~= nil then
  48. keysDown[key] = false
  49. end
  50. end
  51. end)
  52.  
  53. -- Flight loop
  54. game:GetService("RunService").RenderStepped:Connect(function()
  55. if not flying then return end
  56.  
  57. local char = player.Character
  58. if not char or not char:FindFirstChild("HumanoidRootPart") then return end
  59. local rootPart = char.HumanoidRootPart
  60.  
  61. -- Prevent falling
  62. rootPart.Velocity = Vector3.zero
  63.  
  64. -- Get camera directions
  65. local camCF = camera.CFrame
  66. local forward = camCF.LookVector
  67. local right = camCF.RightVector
  68. local up = Vector3.new(0, 1, 0)
  69.  
  70. -- Calculate movement
  71. moveDirection = Vector3.zero
  72. if keysDown.W then moveDirection += forward end
  73. if keysDown.S then moveDirection -= forward end
  74. if keysDown.A then moveDirection -= right end
  75. if keysDown.D then moveDirection += right end
  76. if keysDown.Space then moveDirection += up end
  77. if keysDown.LeftShift then moveDirection -= up end
  78.  
  79. if moveDirection.Magnitude > 0 then
  80. moveDirection = moveDirection.Unit
  81. local newPos = rootPart.Position + moveDirection * flySpeed
  82. rootPart.CFrame = CFrame.new(newPos, newPos + camCF.LookVector)
  83. end
  84. end)
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement