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

KeyDown not working right?

Asked by
samfun123 235 Moderation Voter
9 years ago

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

Log in to vote
0
Answered by
HexC3D 830 Moderation Voter
9 years ago
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.

0
Do have some code that would disable the "/" so that I could use it? samfun123 235 — 9y
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. HexC3D 830 — 9y
Ad

Answer this question