-- 🌀━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Auto Fly ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━🌀

local isFlyModeActive = false
local flyModeThread = nil

local function toggleFlyMode()
isFlyModeActive = not isFlyModeActive

if isFlyModeActive then
flyModeThread = spawn(function()
while isFlyModeActive do
pcall(function()
local player = game:GetService("Players").LocalPlayer
local character = player.Character
if not character then return end

local humanoid = character:FindFirstChild("Humanoid")
local rootPart = character:FindFirstChild("HumanoidRootPart")
if not humanoid or not rootPart then return end

local camera = workspace.CurrentCamera
local UIS = game:GetService("UserInputService")
local flySpeed = humanoid.WalkSpeed * 0.9

-- Check if Gyro exists in rootPart, create if not
local Gyro = rootPart:FindFirstChild("Gyro")
if not Gyro then
Gyro = Instance.new("BodyGyro")
Gyro.Name = "Gyro"
Gyro.P = 9e4
Gyro.MaxTorque = Vector3.new(9e9, 9e9, 9e9)
Gyro.Parent = rootPart
end

-- Check if BodyVelocity exists in rootPart, create if not
local Velocity = rootPart:FindFirstChild("BodyVelocity")
if not Velocity then
Velocity = Instance.new("BodyVelocity")
Velocity.Name = "BodyVelocity"
Velocity.MaxForce = Vector3.new(9e9, 9e9, 9e9)
Velocity.Velocity = Vector3.zero
Velocity.Parent = rootPart
end

-- Set platform stand
humanoid.PlatformStand = true

-- Update Gyro CFrame
Gyro.CFrame = CFrame.new(rootPart.Position, rootPart.Position + camera.CFrame.LookVector)

-- Calculate movement direction based on key presses
local moveDir = Vector3.new(0,0,0)
if UIS:IsKeyDown(Enum.KeyCode.W) then moveDir = moveDir + camera.CFrame.LookVector end
if UIS:IsKeyDown(Enum.KeyCode.S) then moveDir = moveDir - camera.CFrame.LookVector end
if UIS:IsKeyDown(Enum.KeyCode.A) then moveDir = moveDir - camera.CFrame.RightVector end
if UIS:IsKeyDown(Enum.KeyCode.D) then moveDir = moveDir + camera.CFrame.RightVector end

-- Apply speed
if moveDir.Magnitude > 0 then moveDir = moveDir.Unit * flySpeed end
Velocity.Velocity = moveDir
end)

task.wait(0.1)
end
end)
else
-- Clean up when toggled off
pcall(function()
local player = game:GetService("Players").LocalPlayer
local character = player.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
local rootPart = character:FindFirstChild("HumanoidRootPart")

if humanoid then humanoid.PlatformStand = false end

if rootPart then
local Gyro = rootPart:FindFirstChild("Gyro")
local Velocity = rootPart:FindFirstChild("BodyVelocity")

if Gyro then Gyro:Destroy() end
if Velocity then Velocity:Destroy() end
end
end
end)
end

return isFlyModeActive
end

if not isFlyModeActive then
toggleFlyMode()
end