Im attempting to make a inventory system, when you click TAB the gui will be brought up and then i want your mouse to be able to move freely so you can mess with the inventory and things, and when you click TAB again the gui will be no longer visible then the mouse lock will be back.
Heres the script i have so far i just need the mouse part figured out.
local hotkey = Enum.KeyCode.Tab
local UIS = game:GetService("UserInputService") local open = false
UIS.InputBegan:Connect(function(key, gp) if key.KeyCode == hotkey then if UIS:GetFocusedTextBox() == nil then if script.Parent.Visible == true then script.Parent.Visible = false
--Mouse unlock else script.Parent.Visible = true --Mouse lock end end end
end)
You can lock the mouse using UserInputService's MouseBehavior
property.
It goes like so:
local UserInputService = game:GetService("UserInputService") UserInputService.MouseBehavior = Enum.MouseBehaviour.LockCenter -- mouse locked to middle of screen