How to prevent key from being typed as result of UserInputService?

Hello,
I’ve been working on a system similar to roblox chat where when you press / it selects a textbox. However, It types the / into the text box as well as focusing. This only occurs on roblox client and does not happen on studio for some odd reason.

local uis = game:GetService("UserInputService")
local msgBox = gui.MessageBox

-- ...

uis.InputBegan:Connect(function(input, gp)
	if gp then return end

	if input.KeyCode == Enum.KeyCode.Slash then
		msgBox:CaptureFocus()
		msgBox.Text = ""
	end
end)

I have tried using task.wait() and task.defer, however, it did not yield any different results, and I don’t want any delays just like the native chat box would not have any extra delay.

I found this response and it seems pretty similar towards your situation How do I disable the escape keybind that opens the ROBLOX menu? - Help and Feedback / Scripting Support - Developer Forum | Roblox

this is not a good solution as it abused a bug that is likely already fixed. Also, their situation was different as I have already disabled the chat.

Maybe try changing the text to “” on the server. This seems unreliable and might not work but this is all I can think of for now.

Sorry let me clarify, does the textbox.text says / on the client

yes it says / on the client. It is actually inputted into the textbox. When i print the contents of the texbox, it confirms the slash is there. Also, when i send it to the server it has the /. I don’t see how changing it on the server would work when it’s a playergui component. Especially since the input is all handled inside a local script.

you can try doing a variable called firsttype and make it true and do ui.Focus:Connect() and then make the first variable called firsttype true and do another one that when ui.FocusLost:Connect() and if the string == “” then firsttype = false. for what happens when ui.Focus if the firsttype == false then string == “”. I hope this works but I currently have no way to prove it because im going to be honest im horrible at gui… Especially when it comes towards handling stuff between client and server side.

If you want me to clarify you can ask but again, I have no way of proving it works or not and im just naming solutions that have a 10% chance at most working

I fixed this by doing

msgBox.Text = msgBox.Text:gsub("/", "")

It also had no delay like I was concerned about.

2 Likes

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