
Key RequiredUniversal

-- Services
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
-- Player references
local player = Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local humanoid = char:WaitForChild("Humanoid")
local root = char:WaitForChild("HumanoidRootPart")
-- GUI
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "FlyToggleUI"
screenGui.ResetOnSpawn = false
screenGui.Parent = player:WaitForChild("PlayerGui")
local button = Instance.new("TextButton")
button.Name = "ToggleButton"
button.Size = UDim2.new(0, 30, 0, 30)
button.Position = UDim2.new(0, 20, 0, 100)
button.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
button.Text = "🦇" -- Bat emoji
button.TextColor3 = Color3.new(1, 1, 1)
button.Font = Enum.Font.SourceSansBold
button.TextScaled = true
button.Active = true
button.Draggable = true
button.Parent = screenGui
-- Flying variables
local flying = false
local flyConnection
local flyBV, flyBG
local flySpeed = 100
local hoverAmplitude = 2
local hoverSpeed = 2
local hoverTime = 0
-- Update references on respawn
local function updateCharacter(newChar)
char = newChar
humanoid = char:WaitForChild("Humanoid")
root = char:WaitForChild("HumanoidRootPart")
end
player.CharacterAdded:Connect(updateCharacter)
-- Start flying
local function startFly()
if flying then return end
flying = true
humanoid.PlatformStand = true
flyBV = Instance.new("BodyVelocity")
flyBV.MaxForce = Vector3.new(1e5,1e5,1e5)
flyBV.Velocity = Vector3.new(0,0,0)
flyBV.Parent = root
flyBG = Instance.new("BodyGyro")
flyBG.MaxTorque = Vector3.new(1e5,1e5,1e5)
flyBG.P = 3000
flyBG.CFrame = root.CFrame
flyBG.Parent = root
hoverTime = 0
flyConnection = RunService.RenderStepped:Connect(function(dt)
if not root or not root.Parent then return end
local moveDir = humanoid.MoveDirection
local camForward = workspace.CurrentCamera.CFrame.LookVector
local forwardMag = camForward:Dot(moveDir)
if forwardMag > 0 then
local velocity = camForward.Unit * flySpeed * forwardMag
flyBV.Velocity = velocity
flyBG.CFrame = CFrame.new(root.Position, root.Position + camForward) * CFrame.Angles(math.rad(-90),0,0)
else
hoverTime = hoverTime + dt * hoverSpeed
local hoverOffset = math.sin(hoverTime) * hoverAmplitude
flyBV.Velocity = Vector3.new(0,hoverOffset,0)
flyBG.CFrame = CFrame.new(root.Position, root.Position + camForward)
end
end)
end
-- Stop flying
local function stopFly()
flying = false
humanoid.PlatformStand = false
if flyConnection then flyConnection:Disconnect() flyConnection = nil end
if flyBV then flyBV:Destroy() flyBV = nil end
if flyBG then flyBG:Destroy() flyBG = nil end
end
-- Toggle flying when button clicked
button.MouseButton1Click:Connect(function()
if flying then
stopFly()
button.BackgroundColor3 = Color3.fromRGB(255,0,0)
else
startFly()
button.BackgroundColor3 = Color3.fromRGB(0,255,0)
end
end)No comments yet for this script.



