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

My chatbar won't work, can someone help?

Asked by 10 years ago

Script:

game.Players.LocalPlayer:GetMouse().KeyDown:connect(function(key)
    if key == 47 then
        script.Parent:CaptureFocus()
    end
end)

Here is the problem The capturefocus works fine, the byte is correct. In studio, I click "/" and it works fine. In online, I click "/" and it won't work (I need to press Alt, Ctrl, or Shift with it for it to work) In a local script. No error.

0
Make sure you don't have filtering enabled on.. it's located within Workspace itself :D lomo0987 250 — 10y
0
I'll see if that is problem, if not I'll report back. fireboltofdeath 635 — 10y
0
No, it sadly is off. fireboltofdeath 635 — 10y

2 answers

Log in to vote
1
Answered by 10 years ago

Use the UserInputService for whatever you're trying to do, because the "/" key and the Left-SHIFT key both have the same bytecode.

local UserInput = game:GetService("UserInputService")
UserInput.InputBegan:connect(function(InputObj)
    if InputObj.KeyCode == Enum.KeyCode.Slash then
        --Do code
    end
end)

This is the more effective way of doing it because in order for it to work, you have to press the Slash key, unlike in the keydown event where you could press the Left-SHIFT key and it would still capturefocus. Hope this helped!

Note: For more info on the UserInputService, go here: UserInputService

0
Works! But I noticed it has many bugs, heh, like the starter text: Click blah blah blah to chat stays. Thanks! fireboltofdeath 635 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

Use KeyUp instead of KeyDown. The wiki states some special keys like "/" can be captured by doing KeyUp instead of KeyDown.

Source: http://wiki.roblox.com/index.php?title=KeyDown_(Event)

game.Players.LocalPlayer:GetMouse().KeyUp:connect(function(key)
    if key == 47 then
        script.Parent:CaptureFocus()
    end
end)
0
KeyUp I thought took longer. I am going to take a look at Epix Edit of Kohl's admin commands, I saw a method that let you just press / M39a9am3R 3210 — 10y
0
KeyUp takes the same amount of time. I'd look at TurboFusion's answer which is quite interesting. Not that I've got the UserInputService to work for me before, ha ha! Spongocardo 1991 — 10y
0
Nope. fireboltofdeath 635 — 10y

Answer this question