local player = game.Players.LocalPlayer local char = player.Character or player.CharacterAdded:Wait() local humanoidRootPart = char:WaitForChild("HumanoidRootPart") local flying = false local speed = 50 local bodyVelocity local bodyGyro local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local direction = Vector3.new() -- Toggle fly with F UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.KeyCode == Enum.KeyCode.F then flying = not flying if flying then bodyVelocity = Instance.new("BodyVelocity") bodyVelocity.MaxForce = Vector3.new(1e5, 1e5, 1e5) bodyVelocity.Velocity = Vector3.new() bodyVelocity.Parent = humanoidRootPart bodyGyro = Instance.new("BodyGyro") bodyGyro.MaxTorque = Vector3.new(1e5, 1e5, 1e5) bodyGyro.CFrame = humanoidRootPart.CFrame bodyGyro.Parent = humanoidRootPart else if bodyVelocity then bodyVelocity:Destroy() end if bodyGyro then bodyGyro:Destroy() end end end end) -- Movement controls UserInputService.InputBegan:Connect(function(input) if input.KeyCode == Enum.KeyCode.W then direction = direction + Vector3.new(0, 0, -1) end if input.KeyCode == Enum.KeyCode.S then direction = direction + Vector3.new(0, 0, 1) end if input.KeyCode == Enum.KeyCode.A then direction = direction + Vector3.new(-1, 0, 0) end if input.KeyCode == Enum.KeyCode.D then direction = direction + Vector3.new(1, 0, 0) end if input.KeyCode == Enum.KeyCode.Space then direction = direction + Vector3.new(0, 1, 0) end if input.KeyCode == Enum.KeyCode.LeftControl then direction = direction + Vector3.new(0, -1, 0) end end) UserInputService.InputEnded:Connect(function(input) if input.KeyCode == Enum.KeyCode.W then direction = direction - Vector3.new(0, 0, -1) end if input.KeyCode == Enum.KeyCode.S then direction = direction - Vector3.new(0, 0, 1) end if input.KeyCode == Enum.KeyCode.A then direction = direction - Vector3.new(-1, 0, 0) end if input.KeyCode == Enum.KeyCode.D then direction = direction - Vector3.new(1, 0, 0) end if input.KeyCode == Enum.KeyCode.Space then direction = direction - Vector3.new(0, 1, 0) end if input.KeyCode == Enum.KeyCode.LeftControl then direction = direction - Vector3.new(0, -1, 0) end end) RunService.RenderStepped:Connect(function() if flying and bodyVelocity and bodyGyro then local camera = workspace.CurrentCamera local moveDir = camera.CFrame:VectorToWorldSpace(direction) bodyVelocity.Velocity = moveDir * speed bodyGyro.CFrame = camera.CFrame end end)