Advertisement
c00lrussian

Untitled

Dec 11th, 2023 (edited)
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. -- Dependencies
  2. local Players = game:GetService("Players")
  3. local LocalPlayer = Players.LocalPlayer
  4. local RunService = game:GetService("RunService")
  5.  
  6. -- Variables
  7. local FlyEnabled = false
  8. local FlySpeed = 10
  9. local MaxSpeed = 20
  10.  
  11. -- Functions
  12. function Fly(Enabled)
  13. if Enabled then
  14. local Character = LocalPlayer.Character
  15. if Character and Character:FindFirstChild("HumanoidRootPart") then
  16. local RootPart = Character:FindFirstChild("HumanoidRootPart")
  17. RootPart.CanCollide = false
  18. local Heartbeat = RunService.Heartbeat:Connect(function()
  19. local Direction = Vector3.new()
  20. if game.IsKeyDown(Enum.KeyCode.W) then
  21. Direction = Vector3.new(0, 0, FlySpeed)
  22. elseif game.IsKeyDown(Enum.KeyCode.S) then
  23. Direction = Vector3.new(0, 0, -FlySpeed)
  24. end
  25. if game.IsKeyDown(Enum.KeyCode.A) then
  26. Direction = Vector3.new(-FlySpeed, 0, 0)
  27. elseif game.IsKeyDown(Enum.KeyCode.D) then
  28. Direction = Vector3.new(FlySpeed, 0, 0)
  29. end
  30. local Camera = workspace.CurrentCamera
  31. Direction = Camera:WorldToViewportPoint(RootPart.Position) - RootPart.Position
  32. Direction.Y = 0
  33. RootPart.CFrame = CFrame.new(RootPart.Position, RootPart.Position + Direction)
  34. end)
  35. end
  36. else
  37. local Character = LocalPlayer.Character
  38. if Character and Character:FindFirstChild("HumanoidRootPart") then
  39. local RootPart = Character:FindFirstChild("HumanoidRootPart")
  40. RootPart.CanCollide = true
  41. RunService.Heartbeat:Disconnect(Heartbeat)
  42. end
  43. end
  44. end
  45.  
  46. -- Mobile support
  47. local TouchControls = {}
  48. local Touched = false
  49.  
  50. local function HandleTouch(Input)
  51. if Input.UserInputState == Enum.UserInputState.Begin then
  52. Touched = true
  53. if Input.Position.X < 0.5 then
  54. TouchControls.Left = true
  55. elseif Input.Position.X > 0.5 then
  56. TouchControls.Right = true
  57. end
  58. elseif Input.UserInputState == Enum.UserInputState.End then
  59. Touched = false
  60. TouchControls.Left = false
  61. TouchControls.Right = false
  62. end
  63. end
  64.  
  65. workspace.CurrentCamera.Touched:Connect(HandleTouch)
  66.  
  67. -- GUI
  68. local Gui = Instance.new("ScreenGui")
  69. local Frame = Instance.new("Frame")
  70.  
  71. local TitleLabel = Instance.new("TextLabel")
  72. TitleLabel.Text = "Scriptonite Fly"
  73. TitleLabel.Position = UDim2.new(0.5, 0, 0.25, 0)
  74. TitleLabel.FontSize = 24
  75.  
  76. local FlyButton = Instance.new("TextButton")
  77. FlyButton.Text = "Fly"
  78. FlyButton.Position = UDim2.new(0.5, 0, 0.5, 0)
  79. FlyButton.MouseButton1Click:Connect(function()
  80. FlyEnabled = not FlyEnabled
  81. if FlyEnabled then
  82. FlyButton.Text = "Land"
  83. else
  84. FlyButton.Text = "Fly"
  85. end
  86. Fly(FlyEnabled)
  87. end)
  88.  
  89. local SpeedSlider = Instance.new("Slider")
  90. SpeedSlider.Min = 10
  91. SpeedSlider.Max = MaxSpeed
  92. SpeedSlider.Value = FlySpeed
  93. SpeedSlider.Position = UDim2.new(0.5, 0, 0.75, 0)
  94. SpeedSlider.Changed:Connect(function()
  95. FlySpeed = SpeedSlider.Value
  96. end)
  97.  
  98. -- This line seems incomplete, please provide additional GUI elements here
  99. Frame:Adopt({TitleLabel, FlyButton, SpeedSlider, -- Add other GUI elements here})
  100.  
  101. -- Update GUI based on mobile controls
  102. RunService.Heartbeat:Connect(function()
  103. if Touched and TouchControls.Left then
  104. Fly(true)
  105. local Direction = Vector3.new(-FlySpeed, 0, 0)
  106. local Camera = workspace.CurrentCamera
  107. Direction = Camera:WorldToViewportPoint(Frame.Position) - Frame.Position
  108. Direction.Y = 0
  109. Frame.CFrame = CFrame.new(Frame.Position, Frame.Position + Direction)
  110. elseif Touched and TouchControls.Right then
  111. Fly(true)
  112. local Direction = Vector3.new(FlySpeed, 0, 0)
  113. local Camera = workspace.CurrentCamera
  114. Direction = Camera:WorldToViewportPoint(Frame.Position) - Frame.Position
  115. Direction.Y = 0
  116. Frame:SetPrimaryPartCFrame(CFrame.new(Frame.Position, Frame.Position + Direction))
  117. end
  118. end)
  119.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement