Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is wrong with the key?

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!

2 answers

✓ Accepted answer

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)

1 comment

0

Thanks!

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.

4 comments

0

I have already disabled the default chat bar, and this is in a local script.

0

Try using KeyUp rather then KeyDown then.

0

Thanks! KeyUp is what I needed

0

:D

This discussion is preserved as it was. New answers, comments, and votes are closed.