Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Mobile-only Fly Button Script (LocalScript inside ScreenGui)
- local Players = game:GetService("Players")
- local UserInputService = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- -- Make sure we only run this on mobile
- if not UserInputService.TouchEnabled then
- script.Disabled = true
- return
- end
- local player = Players.LocalPlayer
- local char = player.Character or player.CharacterAdded:Wait()
- local hrp = char:WaitForChild("HumanoidRootPart")
- local humanoid = char:WaitForChild("Humanoid")
- local flyButton = script.Parent:WaitForChild("FlyButton")
- local flying = false
- local bv
- local function startFly()
- if flying then return end
- flying = true
- flyButton.Text = "STOP FLY"
- bv = Instance.new("BodyVelocity")
- bv.Velocity = Vector3.new(0, 0, 0)
- bv.MaxForce = Vector3.new(0, 0, 0)
- bv.Parent = hrp
- end
- local function stopFly()
- flying = false
- flyButton.Text = "FLY"
- if bv then
- bv:Destroy()
- bv = nil
- end
- end
- flyButton.MouseButton1Down:Connect(function()
- if not flying then
- startFly()
- else
- stopFly()
- end
- end)
- -- Update velocity while flying
- RunService.Heartbeat:Connect(function()
- if flying and bv then
- -- move upward slowly
- bv.MaxForce = Vector3.new(4000, 4000, 4000)
- bv.Velocity = Vector3.new(0, 25, 0)
- end
- end)
Add Comment
Please, Sign In to add comment