For a place i am making, which is in first person, i need to allow my mouse to move while the GUI is open
local player = game.Players.LocalPlayer local mouse = player:GetMouse() local open = false mouse.KeyDown:connect(function(key) if key == "q" then --replace this with the key you want if open == false then open = true script.Parent.ShopFrame.Visible = true elseif open == true then open = false script.Parent.ShopFrame.Visible = false end end end)
what would I have to add or change to allow this?
GUI buttons have a field known as "Modal" that, when true, will unlock the mouse in first person as long as that button has its "Visible" field set to true. I would set it manually in Studio, then you will not have any problems. Hope I helped!
The mouse position can be locked to the center of the screen using MouseBehavior. Setting this property to Enum.MouseBehavior.LockCenter will lock the mouse to the center of the screen, Enum.MouseBehavior.Default will unlock the mouse.
If the mouse is locked, InputChanged will still fire when the player moves the mouse and will pass in the distance the mouse has moved.
local UserInputService = game:GetService("UserInputService") UserInputService.MouseBehavior = Enum.MouseBehavior.LockCenter UserInputService.InputChanged:connect(function(inputObject) if inputObject.UserInputType == Enum.UserInputType.MouseMovement then print("delta is (" .. tostring(inputObject.Delta.x) .. ", " .. tostring(inputObject.Delta.y) .. ")") end end) --All of this will lock the mouse in the center and will tell you the delta
If you want the mouse to be unlocked then use :
local UserInputService = game:GetService("UserInputService") UserInputService.MouseBehavior = Enum.MouseBehavior.Default
Unfortunately, as I know, ROBLOX has a mouse-lock-in feature when you go into first person, therefor you are not able to select any screen GUIs. You must be in third person to select and move screen GUIs.