Hello. I was writing a script for a new chat bar. I have learned how to do it, and I got all the way down to pressing the key to make it focus.
local Mouse = game.Players.LocalPlayer:GetMouse() Mouse.KeyDown:connect(function(Key) if Key == "/" then script.Parent:CaptureFocus() end end)
When I press the "/" key in test mode it works perfect. It focuses on the TextBox and allows me to type. I've also got it programmed to send the chat when the focus is lost (on enterPressed).
My issue is, when I go online and press the "/" key nothing happens. I spam press it, then rage press it, nothing happens. Then, I accidentally press the right shift key and BAM! It focuses. I'm like, okay and type in a message. I press enter and it shows the message. Press "/" nothing happens. Press right shift and it focuses again.
I don't know if the problem is backslash and right shift go off of the same byte code or what. So if someone could help me figure out the problem, I would appreciate it! Thanks!
I had the same problem. Acecateer is right, but what you have to do is use KeyUp
instead of KeyDown
. I fixed the script for you below.
I also used Key.Byte()
to fix any possible problems there.
local Mouse = game.Players.LocalPlayer:GetMouse() Mouse.KeyUp:connect(function(Key) if Key:byte() == 47 then script.Parent:CaptureFocus() end end)
That is because in online mode "/" is already used for the default chat bar.
You can use SetCoreGuiEnabled and disable the default chat bar like this:
game.StarterGui:SetCoreGuiEnabled("Chat", false)
Please note: You must do this in a local script.