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

KeyDown not working right?

I'm currently working on a game and I wanted to make my own Chat GUI. I have the chats displaying on the screen but I wanted to also make a Chat Bar.

My problem is that I am checking for when the player presses the "/" key, but sometimes the event doesn't fire when the player presses that key.

My code :

-- mouse is the players mouse.
-- gui is the chatgui all the gui objects are being stored in.

mouse.KeyDown:connect(function(key)
	if key == "/" then
		gui.ChatBox.ChatBox.Text = ""
		gui.Label:TweenPosition(UDim2.new(0.05,0,1,0), "Out", "Quad", 1, true)
		gui.ChatBox:TweenPosition(UDim2.new(0,0,0.95,0), "Out", "Quad", 1, true)
		gui.ChatBox.ChatBox:CaptureFocus()
	end
end)

Anyone have any ideas to fix this I've seen other games do this but not sure how they did it.

1 answer

✓ Accepted answer
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()
 
Mouse.KeyDown:connect(function(Key)
if key == string.char(47) then -- This is the shift key.
        gui.ChatBox.ChatBox.Text = ""
        gui.Label:TweenPosition(UDim2.new(0.05,0,1,0), "Out", "Quad", 1, true)
        gui.ChatBox:TweenPosition(UDim2.new(0,0,0.95,0), "Out", "Quad", 1, true)
        gui.ChatBox.ChatBox:CaptureFocus()
end)


Special Keys Maybe you can try using ContollerService on wiki to help. I believe this "/" key is already in use for the regular roblox, though I have a feeling that your making a custom chat which gets rid of roblox chat using SetCoreGuiEnabled. But I guess there is a way to unbind the "/" and use it but till then you can use other keys.

2 comments

0

Do have some code that would disable the "/" so that I could use it?

0

I can do that like do it like in Apocalypse rising, Using Controller Service, but I don't get points for this stuff, check how many answers I answered.

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