is there a way to make this fly script support on mobile?
local tool = script.Parent
local Handle = tool:WaitForChild("Handle")
local flying = false
tool.Activated:Connect(function()
flying = true
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local velocity = Instance.new("BodyVelocity", hrp)
velocity.MaxForce = Vector3.new(math.huge/100,math.huge/100,math.huge/100)
while flying do
velocity.Velocity = mouse.Hit.LookVector*100
tool.Deactivated:Connect(function()
flying = false
end)
wait()
end
end)
tool.Deactivated:Connect(function()
flying = false
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
local children = hrp:GetChildren()
for i = 1, #children do
local child = children[i]
if child:IsA("BodyVelocity") then
child:Destroy()
end
end
end)
I’ve made a script for you, when the tool is equipped you can fly and it follows the players camera, works on mobile as well.
Script:
local tool = script.Parent
local players = game:GetService("Players")
local userInputService = game:GetService("UserInputService")
local flying = false
local flySpeed = 50
local player
local humanoid
local bodyVelocity
local camera = game.Workspace.CurrentCamera
local function enableFlying()
if not player or not player.Character then return end
flying = true
if not bodyVelocity then
bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = Vector3.new(0,0,0)
bodyVelocity.MaxForce = Vector3.new(9e9, 9e9, 9e9)
bodyVelocity.P = 10000
bodyVelocity.Parent = player.Character.HumanoidRootPart
end
while flying do
local direction = camera.CFrame.LookVector
bodyVelocity.Velocity = direction * flySpeed
wait(0.1)
end
end
local function disableFlying()
flying = false
if bodyVelocity then
bodyVelocity:Destroy()
end
end
tool.Equipped:Connect(function()
player = players:GetPlayerFromCharacter(tool.Parent)
if player then
enableFlying()
end
end)
tool.Unequipped:Connect(function()
disableFlying()
end)
local tool = script.Parent
local players = game:GetService("Players")
local userInputService = game:GetService("UserInputService")
local flying = false
local flySpeed = 50
local player
local humanoid
local bodyVelocity
local camera = game.Workspace.CurrentCamera
local function enableFlying()
if not player or not player.Character then return end
flying = true
local bodyVelocity = Instance.new("BodyVelocity")
bodyVelocity.Velocity = Vector3.new(0, 0, 0)
bodyVelocity.MaxForce = Vector3.new(9e9, 9e9, 9e9)
bodyVelocity.P = 10000
bodyVelocity.Parent = player.Character.HumanoidRootPart
while flying do
local direction = camera.CFrame.LookVector
bodyVelocity.Velocity = direction * flySpeed
game:GetService("RunService").Heartbeat:Wait()
end
if bodyVelocity then
bodyVelocity:Destroy()
end
end
local function disableFlying()
flying = false
end
tool.Equipped:Connect(function()
player = players:GetPlayerFromCharacter(tool.Parent)
if player then
enableFlying()
end
end)
tool.Unequipped:Connect(function()
disableFlying()
end)