Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

What is wrong with the key?

Asked by 10 years ago

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

Log in to vote
2
Answered by 10 years ago

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)

0
Thanks! TheStudentPilot 75 — 10y
Ad
Log in to vote
1
Answered by
acecateer 130
10 years ago

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.

0
I have already disabled the default chat bar, and this is in a local script. TheStudentPilot 75 — 10y
0
Try using KeyUp rather then KeyDown then. acecateer 130 — 10y
0
Thanks! KeyUp is what I needed TheStudentPilot 75 — 10y
0
:D acecateer 130 — 10y

Answer this question