Advertisement
Umendboy

Localscript Fly script

Jun 25th, 2022
225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. local uis = game:GetService("UserInputService")
  2.  
  3. local isFlying = false
  4.  
  5.  
  6. local camera = workspace.CurrentCamera
  7.  
  8.  
  9. local char = script.Parent
  10.  
  11. local hrp = char:WaitForChild("HumanoidRootPart")
  12.  
  13.  
  14. local bodyPos = Instance.new("BodyPosition")
  15. bodyPos.MaxForce = Vector3.new()
  16. bodyPos.D = 10
  17. bodyPos.P = 100
  18. bodyPos.Parent = hrp
  19.  
  20. local bodyGyro = Instance.new("BodyGyro")
  21. bodyGyro.MaxTorque = Vector3.new()
  22. bodyGyro.D = 10
  23. bodyGyro.Parent = hrp
  24.  
  25.  
  26. uis.InputBegan:Connect(function(input, gameProcessed)
  27.  
  28. if input.KeyCode == Enum.KeyCode.Space and not gameProcessed then
  29.  
  30. isFlying = true
  31. end
  32. end)
  33.  
  34. uis.InputEnded:Connect(function(input, gameProcessed)
  35.  
  36. if input.KeyCode == Enum.KeyCode.Space and not gameProcessed then
  37.  
  38. isFlying = false
  39. end
  40. end)
  41.  
  42.  
  43. game:GetService("RunService").RenderStepped:Connect(function()
  44.  
  45. if isFlying then
  46.  
  47. bodyPos.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
  48. bodyGyro.MaxTorque = Vector3.new(math.huge, math.huge, math.huge)
  49.  
  50.  
  51. bodyPos.Position = hrp.Position +((hrp.Position - camera.CFrame.Position).Unit * 10)
  52.  
  53. bodyGyro.CFrame = CFrame.new(camera.CFrame.Position, hrp.Position)
  54.  
  55.  
  56. else
  57. bodyPos.MaxForce = Vector3.new()
  58. bodyGyro.MaxTorque = Vector3.new()
  59. end
  60. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement