local userInputService = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local camera = workspace.CurrentCamera
local isMouseFree = false
local originalCameraType = camera.CameraType
local function toggleMouse()
isMouseFree = not isMouseFree
if isMouseFree then
-- Фиксируем камеру на месте, чтобы она не бегала за мышей
camera.CameraType = Enum.CameraType.Scriptable
-- Включаем видимость мыши (в старых и новых интерфейсах Roblox это работает стабильно)
userInputService.MouseIconEnabled = true
print("Мышь освобождена!")
else
-- Возвращаем стандартное управление камерой от третьего лица
camera.CameraType = Enum.CameraType.Custom
userInputService.MouseIconEnabled = false
print("Камера возвращена в обычный режим")
end
end
userInputService.InputBegan:Connect(function(input, gameProcessed)
if gameProcessed then return end
-- Переключение по клавише V
if input.KeyCode == Enum.KeyCode.V then
toggleMouse()
end
-- Если мышь свободна и зажали ПКМ — временно возвращаем камеру, чтобы осмотреться
if input.UserInputType == Enum.UserInputType.MouseButton2 and isMouseFree then
camera.CameraType = Enum.CameraType.Custom
end
end)
userInputService.InputEnded:Connect(function(input)
-- Отпустили ПКМ — снова фиксируем камеру и освобождаем курсор
if input.UserInputType == Enum.UserInputType.MouseButton2 and isMouseFree then
camera.CameraType = Enum.CameraType.Scriptable
end
end)