GlobalChat client causing Mouse Lock on PC

I have created a Global Chat system to replicate the chat messages for our game, as it is a single player experience. The chat system is going well for players and they seem more engaged.
However, for PC users after seemingly random periods of time, the camera will become mouse locked and they will be unable to interact with the UI. As the game is UI heavy (it is the main interaction component), it ruins the game for them and they leave. I can see the reduction in play time for PC users drop in the stats.
Client Side script

function OnGlobalChat(Data)
-- Format Data	
	Data = string.gsub(Data, "%[", "")
	Data = string.gsub(Data, "%]", "")
	Data = string.gsub(Data, "\"", "")
	local chatData = string.split(Data, ",")
	local Name = chatData[1]
	local Message = chatData[2]

-- Return if no Name, Message or it is Local Player chat	
	if not Name then return end
	if Name == player.Name then return end
	if not Message then return end
-- Show Message in Chat
	StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = "[" .. Name .. "]: " .. Message,
		Color = playerTable[Name],
		Font = Enum.Font.SourceSansBold,
	})
end
--EVENTS
GlobalChat.OnClientEvent:Connect(OnGlobalChat)

I can’t see any logical reason why this should be happening. All worked fine before the chat system was added.
StarterPlayer settings:

Can somebody please advise what I am doing wrong.

There is most likely another script doing this. Try doing Find all / Replace all and find a phrase containing “Enum.MouseBehavior”.

Literally the only code change has been the introduction of the global chat system. I did a search for MouseBehavior, nothing found. The only mouse related activity in the scripts simply disables the scroll wheel:

ContextActionService:BindAction(
	"Action",
	function ()
		return Enum.ContextActionResult.Sink
	end,
	false,
	Enum.UserInputType.MouseWheel
)

That doesn’t seem completely related, though you could try adjusting the priority of the bound action.

Thanks for the idea, I will test that out shortly.
I was unsure whether something in StartPlayer settings was somehow wrong and hadn’t been noticed before the chat was enabled. I just want the computer player zoomed in fully, able to look around with right-click and to have full mouse movement for UI interaction.

OK. Changed it to BindActionAtPriority with priority 1 (lowest). I will play test and hopefully see if it works soon enough.

Hmm. Still locks. Are there any mouse lock events I can monitor to see exactly when it happens? I can’t tell if it is when I enter the chat window or if it is tabbing in and out of the Roblox client window

The only way I have detected the state of the mouse lock is if UserInputService.MouseBehavior == Enum.MouseBehavior.LockCenter. I guess you could put a script in there to change it back to normal automatically, but this would mess up first person, unless there are some checks to determine if the LocalTransparencyModifier of the limbs is 1 or if the camera is close enough to the camera subject.

1 Like

I think you have solved it, till testing tho. I tried capture a Changed signal on MouseBehavior, but it never triggered, so just added a hacky while true loop. Tested OK for 15 minutes. I will test again later today.

1 Like