Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local UserInputService = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local Players = game:GetService("Players")
- local player = Players.LocalPlayer
- local character = player.Character or player.CharacterAdded:Wait()
- local humanoid = character:WaitForChild("Humanoid")
- local hrp = character:WaitForChild("HumanoidRootPart")
- local camera = game.Workspace.CurrentCamera
- -- Variables
- local isFlying = false
- local flySpeed = 50
- local velocities = {
- forward = 0,
- horizontal = 0,
- vertical = 0
- }
- local bodyVelocity = nil
- -- GUI Setup
- local FlyGui = Instance.new("ScreenGui")
- FlyGui.Name = "FlyGui"
- FlyGui.Parent = player:WaitForChild("PlayerGui")
- FlyGui.ResetOnSpawn = false
- local Frame = Instance.new("Frame")
- Frame.Parent = FlyGui
- Frame.BackgroundColor3 = Color3.fromRGB(30, 30, 30)
- Frame.Position = UDim2.new(0.75, 0, 0.6, 0)
- Frame.Size = UDim2.new(0, 180, 0, 180)
- Frame.BorderSizePixel = 0
- local UICorner = Instance.new("UICorner")
- UICorner.CornerRadius = UDim.new(0.1, 0)
- UICorner.Parent = Frame
- local UIGradient = Instance.new("UIGradient")
- UIGradient.Color = ColorSequence.new{
- ColorSequenceKeypoint.new(0, Color3.fromRGB(50, 100, 255)),
- ColorSequenceKeypoint.new(1, Color3.fromRGB(100, 50, 200))
- }
- UIGradient.Parent = Frame
- local GridLayout = Instance.new("UIGridLayout")
- GridLayout.Parent = Frame
- GridLayout.CellSize = UDim2.new(0, 50, 0, 50)
- GridLayout.CellPadding = UDim2.new(0, 10, 0, 10)
- GridLayout.StartOrder = Enum.SortOrder.LayoutOrder
- -- Button Creation Function
- local function createButton(name, text)
- local button = Instance.new("TextButton")
- button.Name = name
- button.Parent = Frame
- button.BackgroundColor3 = Color3.fromRGB(80, 80, 120)
- button.Font = Enum.Font.Gotham
- button.Text = text
- button.TextColor3 = Color3.fromRGB(255, 255, 255)
- button.TextScaled = true
- button.ZIndex = 2
- local corner = UICorner:Clone()
- corner.Parent = button
- return button
- end
- -- Create Buttons
- local forwardButton = createButton("Forward", "↑")
- local upButton = createButton("Up", "⬆")
- local backwardButton = createButton("Backward", "↓")
- local leftButton = createButton("Left", "←")
- local flyButton = createButton("Fly", "Fly")
- local rightButton = createButton("Right", "→")
- local speedMinus = createButton("SpeedMinus", "-")
- local downButton = createButton("Down", "⬇")
- local speedPlus = createButton("SpeedPlus", "+")
- -- Connect Events
- flyButton.MouseButton1Click:Connect(function()
- isFlying = not isFlying
- flyButton.Text = isFlying and "Unfly" or "Fly"
- end)
- speedPlus.MouseButton1Click:Connect(function()
- flySpeed = flySpeed + 10
- end)
- speedMinus.MouseButton1Click:Connect(function()
- flySpeed = math.max(10, flySpeed - 10)
- end)
- -- Direction Buttons
- forwardButton.MouseButton1Down:Connect(function() velocities.forward = flySpeed end)
- forwardButton.MouseButton1Up:Connect(function() velocities.forward = 0 end)
- backwardButton.MouseButton1Down:Connect(function() velocities.forward = -flySpeed end)
- backwardButton.MouseButton1Up:Connect(function() velocities.forward = 0 end)
- leftButton.MouseButton1Down:Connect(function() velocities.horizontal = -flySpeed end)
- leftButton.MouseButton1Up:Connect(function() velocities.horizontal = 0 end)
- rightButton.MouseButton1Down:Connect(function() velocities.horizontal = flySpeed end)
- rightButton.MouseButton1Up:Connect(function() velocities.horizontal = 0 end)
- upButton.MouseButton1Down:Connect(function() velocities.vertical = flySpeed end)
- upButton.MouseButton1Up:Connect(function() velocities.vertical = 0 end)
- downButton.MouseButton1Down:Connect(function() velocities.vertical = -flySpeed end)
- downButton.MouseButton1Up:Connect(function() velocities.vertical = 0 end)
- -- Fly Logic
- RunService.RenderStepped:Connect(function()
- if isFlying then
- if not bodyVelocity then
- bodyVelocity = Instance.new("BodyVelocity")
- bodyVelocity.Name = "FlyVelocity"
- bodyVelocity.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
- bodyVelocity.Parent = hrp
- humanoid.PlatformStand = true
- end
- local velocity = (camera.CFrame.LookVector * velocities.forward) +
- (camera.CFrame.RightVector * velocities.horizontal) +
- Vector3.new(0, velocities.vertical, 0)
- bodyVelocity.Velocity = velocity
- else
- if bodyVelocity then
- bodyVelocity:Destroy()
- bodyVelocity = nil
- humanoid.PlatformStand = false
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement