Mouse Unlocking Issues (Modal not working)

So I’m making a spawn menu for this gmod-like game and everything works so far except for the mouse unlocking when activating the spawn menu. (Modal does not work)
Here is the script:

local menu = script.Parent
local player = game.Players.LocalPlayer
local uis = game:GetService("UserInputService")
local mouse = player:GetMouse()

uis.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		uis.MouseBehavior = Enum.MouseBehavior.Default
		mouse.Icon = "rbxassetid://16322948261"
		menu.Visible = true
	end
end)

uis.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Q then
		uis.MouseBehavior = Enum.MouseBehavior.LockCenter
		mouse.Icon = "rbxassetid://16305588060"
		menu.Visible = false
	end
end)

Here is a video:

1 Like

First of all, you should put this in the scripting support category. But, this is an easy fix. Instead of using UserInputService.MouseBehavior, add a text button, make it tiny and invisible, and switch the modal property to true whenever you want the mouse to be unlocked. It sounds weird, but I believe it works.

2 Likes

I had a text label and not a text button, my bad

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.