Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to allow mouse to move in a GUI while in first person? [UNSOLVED]

Asked by
xancor1 10
9 years ago

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?

0
forgot to say, the mouse needs to be able to move when the shop is open, but lock in the middle again when it closes xancor1 10 — 9y

4 answers

Log in to vote
2
Answered by 8 years ago

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!

Ad
Log in to vote
1
Answered by 7 years ago

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
Log in to vote
0
Answered by 9 years ago

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.

0
is there any way i could switch it to third person in the script? xancor1 10 — 9y
Log in to vote
0
Answered by 7 years ago

Just turn Modal on inside the GUI.

Answer this question