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

My chatbar won't work, can someone help?

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.

3 comments

0

Make sure you don't have filtering enabled on.. it's located within Workspace itself :D

0

I'll see if that is problem, if not I'll report back.

0

No, it sadly is off.

2 answers

✓ Accepted answer

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

1 comment

0

Works! But I noticed it has many bugs, heh, like the starter text: Click blah blah blah to chat stays. Thanks!

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)

3 comments

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 /

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!

0

Nope.

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