Загрузка данных


local UserInputService = game:GetService("UserInputService")
local Players = game:GetService("Players")

local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoidRootPart = character:WaitForChild("HumanoidRootPart")

local isFlying = false
local flySpeed = 50 -- Скорость полета

-- Функция для включения/выключения полета
local function toggleFly()
	isFlying = not isFlying
	
	if isFlying then
		-- Отключаем гравитацию для персонажа (опционально)
		character:WaitForChild("Humanoid").PlatformStand = true
		
		-- Создаем силу для полета
		local bodyVelocity = Instance.new("BodyVelocity")
		bodyVelocity.Name = "FlyVelocity"
		bodyVelocity.MaxForce = Vector3.new(4000, 4000, 4000)
		bodyVelocity.Velocity = Vector3.new(0, 0, 0)
		bodyVelocity.Parent = humanoidRootPart
		
		-- Управление полетом (упрощенное)
		while isFlying and character do
			wait()
			if character and humanoidRootPart then
				-- Здесь можно добавить логику направления полета от WASD
				-- Для примера просто держим высоту или двигаем вперед
				bodyVelocity.Velocity = Vector3.new(0, flySpeed * 0.5, 0) 
			else
				break
			end
		end
		
		-- Очистка при выключении
		if bodyVelocity then
			bodyVelocity:Destroy()
		end
		character:WaitForChild("Humanoid").PlatformStand = false
	else
		-- Логика выключения уже обработана в цикле выше, 
		-- но можно добавить сброс скорости
		if humanoidRootPart:FindFirstChild("FlyVelocity") then
			humanoidRootPart.FlyVelocity:Destroy()
		end
		character:WaitForChild("Humanoid").PlatformStand = false
	end
end

-- Отслеживание нажатия клавиши F
UserInputService.InputBegan:Connect(function(input, gameProcessed)
	if gameProcessed then return end -- Игнорировать, если игрок печатает в чате
	
	if input.KeyCode == Enum.KeyCode.F then
		toggleFly()
	end
end)