Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Dependencies
- local Players = game:GetService("Players")
- local LocalPlayer = Players.LocalPlayer
- local RunService = game:GetService("RunService")
- -- Variables
- local FlyEnabled = false
- local FlySpeed = 10
- local MaxSpeed = 20
- -- Functions
- function Fly(Enabled)
- if Enabled then
- local Character = LocalPlayer.Character
- if Character and Character:FindFirstChild("HumanoidRootPart") then
- local RootPart = Character:FindFirstChild("HumanoidRootPart")
- RootPart.CanCollide = false
- local Heartbeat = RunService.Heartbeat:Connect(function()
- local Direction = Vector3.new()
- if game.IsKeyDown(Enum.KeyCode.W) then
- Direction = Vector3.new(0, 0, FlySpeed)
- elseif game.IsKeyDown(Enum.KeyCode.S) then
- Direction = Vector3.new(0, 0, -FlySpeed)
- end
- if game.IsKeyDown(Enum.KeyCode.A) then
- Direction = Vector3.new(-FlySpeed, 0, 0)
- elseif game.IsKeyDown(Enum.KeyCode.D) then
- Direction = Vector3.new(FlySpeed, 0, 0)
- end
- local Camera = workspace.CurrentCamera
- Direction = Camera:WorldToViewportPoint(RootPart.Position) - RootPart.Position
- Direction.Y = 0
- RootPart.CFrame = CFrame.new(RootPart.Position, RootPart.Position + Direction)
- end)
- end
- else
- local Character = LocalPlayer.Character
- if Character and Character:FindFirstChild("HumanoidRootPart") then
- local RootPart = Character:FindFirstChild("HumanoidRootPart")
- RootPart.CanCollide = true
- RunService.Heartbeat:Disconnect(Heartbeat)
- end
- end
- end
- -- Mobile support
- local TouchControls = {}
- local Touched = false
- local function HandleTouch(Input)
- if Input.UserInputState == Enum.UserInputState.Begin then
- Touched = true
- if Input.Position.X < 0.5 then
- TouchControls.Left = true
- elseif Input.Position.X > 0.5 then
- TouchControls.Right = true
- end
- elseif Input.UserInputState == Enum.UserInputState.End then
- Touched = false
- TouchControls.Left = false
- TouchControls.Right = false
- end
- end
- workspace.CurrentCamera.Touched:Connect(HandleTouch)
- -- GUI
- local Gui = Instance.new("ScreenGui")
- local Frame = Instance.new("Frame")
- local TitleLabel = Instance.new("TextLabel")
- TitleLabel.Text = "Scriptonite Fly"
- TitleLabel.Position = UDim2.new(0.5, 0, 0.25, 0)
- TitleLabel.FontSize = 24
- local FlyButton = Instance.new("TextButton")
- FlyButton.Text = "Fly"
- FlyButton.Position = UDim2.new(0.5, 0, 0.5, 0)
- FlyButton.MouseButton1Click:Connect(function()
- FlyEnabled = not FlyEnabled
- if FlyEnabled then
- FlyButton.Text = "Land"
- else
- FlyButton.Text = "Fly"
- end
- Fly(FlyEnabled)
- end)
- local SpeedSlider = Instance.new("Slider")
- SpeedSlider.Min = 10
- SpeedSlider.Max = MaxSpeed
- SpeedSlider.Value = FlySpeed
- SpeedSlider.Position = UDim2.new(0.5, 0, 0.75, 0)
- SpeedSlider.Changed:Connect(function()
- FlySpeed = SpeedSlider.Value
- end)
- Frame:Adopt({TitleLabel, FlyButton, SpeedSlider})
- Gui:Adopt(Frame)
- -- Update GUI based on mobile controls
- RunService.Heartbeat:Connect(function()
- if Touched and TouchControls.Left then
- Fly(true)
- local Direction = Vector3.new(-FlySpeed, 0, 0)
- local Camera = workspace.CurrentCamera
- Direction = Camera:WorldToViewportPoint(Frame.Position) - Frame.Position
- Direction.Y = 0
- Frame.CFrame = CFrame.new(Frame.Position, Frame.Position + Direction)
- elseif Touched and TouchControls.Right then
- Fly(true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement