kill21_2

Untitled

Mar 23rd, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. local flyspeed = 300
  2. local flying = false
  3. local maxdistance = 100000000000000 --using math.huge makes this script wonky
  4. local uiservice = game.UserInputService
  5. local lplr = game.Players.LocalPlayer
  6. local mouse = lplr:GetMouse()
  7. local function GetVelocity(pos1,pos2,StudsPerSecond)
  8. local distance = (pos2 - pos1)
  9. local mag = distance.Magnitude
  10. return (distance/mag)*StudsPerSecond
  11. end
  12. local function getkey(keycode)
  13. local key = tostring(keycode):lower()
  14. local findcode, a = key:find("keycode.")
  15. return key:sub(a+1)
  16. end
  17. local keys = {}
  18. game.RunService.Heartbeat:connect(function()
  19. pcall(function()
  20. local hrp
  21. for i,v in pairs(workspace.Vehicles:GetChildren()) do
  22. if pcall(function() return v.Engine and v.Seat.PlayerName end) then
  23. if v.Seat.PlayerName.Value == lplr.Name then
  24. hrp = v.Engine
  25. break
  26. else
  27. hrp = nil
  28. end
  29. end
  30. end
  31. if not hrp then
  32. flying = false
  33. lplr.Character.Humanoid.CameraOffset = Vector3.new(0,0,0)
  34. end
  35. if flying then
  36. local cam = workspace.Camera
  37. end
  38. local frontoffset = CFrame.new() + Vector3.new(0,0,-maxdistance)
  39. local backoffset = CFrame.new() + Vector3.new(0,0,maxdistance)
  40. local leftoffset = CFrame.new() + Vector3.new(-maxdistance,0,0)
  41. local rightoffset = CFrame.new() + Vector3.new(maxdistance,0,0)
  42. local velocity = Vector3.new()
  43. if flying then
  44. if keys.w_active then
  45. velocity = velocity + GetVelocity(hrp.Position,(hrp.CFrame*frontoffset).Position,flyspeed)
  46. end
  47. if keys.s_active then
  48. velocity = velocity + GetVelocity(hrp.Position,(hrp.CFrame*backoffset).Position,flyspeed)
  49. end
  50. if keys.a_active then
  51. velocity = velocity + GetVelocity(hrp.Position,(hrp.CFrame*leftoffset).Position,flyspeed)
  52. end
  53. if keys.d_active then
  54. velocity = velocity + GetVelocity(hrp.Position,(hrp.CFrame*rightoffset).Position,flyspeed)
  55. end
  56. hrp.Velocity = velocity
  57. hrp.CFrame = CFrame.new(hrp.Position, (workspace.Camera.CFrame*frontoffset).Position)
  58. end
  59. if flying and not keys.w_active and not keys.a_active and not keys.s_active and not keys.d_active then
  60. hrp.Velocity = Vector3.new(0,1.005,0)
  61. end
  62. end)
  63. end)
  64. uiservice.InputBegan:connect(function(key,processed)
  65. if processed then return end
  66. if key.KeyCode == Enum.KeyCode.F and game.UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then
  67. flying = not flying
  68. if flying then
  69. lplr.Character.Humanoid.CameraOffset = Vector3.new(2,0,0)
  70. else
  71. lplr.Character.Humanoid.CameraOffset = Vector3.new(0,0,0)
  72. end
  73. end
  74. keys[getkey(key.KeyCode).."_active"] = true
  75. end)
  76. uiservice.InputEnded:connect(function(key)
  77. keys[getkey(key.KeyCode).."_active"] = false
  78. end)
Add Comment
Please, Sign In to add comment