local UserInputService = game:GetService("UserInputService") local Players = game:GetService("Players") local RunService = game:GetService("RunService") local player = Players.LocalPlayer local character = player.Character or player.CharacterAdded:Wait() local humanoid = character:WaitForChild("Humanoid") local rootPart = character:WaitForChild("HumanoidRootPart") -- Настройки local FLY_KEY = Enum.KeyCode.F local BASE_SPEED = 50 local BOOST_MULTIPLIER = 2 local isFlying = false local flyConnection -- Управление local controls = { Forward = false, Backward = false, Left = false, Right = false, Up = false, Down = false } -- Настройка управления UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.KeyCode == FLY_KEY then toggleFlight() end -- Управление движением if isFlying then if input.KeyCode == Enum.KeyCode.W then controls.Forward = true end if input.KeyCode == Enum.KeyCode.S then controls.Backward = true end if input.KeyCode == Enum.KeyCode.A then controls.Left = true end if input.KeyCode == Enum.KeyCode.D then controls.Right = true end if input.KeyCode == Enum.KeyCode.Space then controls.Up = true end if input.KeyCode == Enum.KeyCode.LeftShift then controls.Down = true end end end) UserInputService.InputEnded:Connect(function(input) if input.KeyCode == Enum.KeyCode.W then controls.Forward = false end if input.KeyCode == Enum.KeyCode.S then controls.Backward = false end if input.KeyCode == Enum.KeyCode.A then controls.Left = false end if input.KeyCode == Enum.KeyCode.D then controls.Right = false end if input.KeyCode == Enum.KeyCode.Space then controls.Up = false end if input.KeyCode == Enum.KeyCode.LeftShift then controls.Down = false end end) function toggleFlight() isFlying = not isFlying if isFlying then humanoid.PlatformStand = true startFlight() else humanoid.PlatformStand = false stopFlight() end end function startFlight() flyConnection = RunService.Heartbeat:Connect(function(delta) if not isFlying or not rootPart then return end local direction = Vector3.new() local speed = BASE_SPEED -- Проверка на ускорение if UserInputService:IsKeyDown(Enum.KeyCode.LeftControl) then speed = speed * BOOST_MULTIPLIER end -- Расчет направления if controls.Forward then direction = direction + rootPart.CFrame.LookVector end if controls.Backward then direction = direction - rootPart.CFrame.LookVector end if controls.Left then direction = direction - rootPart.CFrame.RightVector end if controls.Right then direction = direction + rootPart.CFrame.RightVector end if controls.Up then direction = direction + Vector3.new(0, 1, 0) end if controls.Down then direction = direction + Vector3.new(0, -1, 0) end -- Применение движения if direction.Magnitude > 0 then direction = direction.Unit rootPart.Velocity = direction * speed else rootPart.Velocity = Vector3.new(0, 0, 0) end end) end function stopFlight() if flyConnection then flyConnection:Disconnect() flyConnection = nil end if rootPart then rootPart.Velocity = Vector3.new(0, 0, 0) end end -- Очистка при смерти humanoid.Died:Connect(function() stopFlight() isFlying = false humanoid.PlatformStand = false end)