Key Binds - Chat

I’m using a script that lets me press “H” and it will remove my player’s helmet. However, this works even when the player is typing in the Roblox chat. Is there a way I can make it so it only removes the helmet if they aren’t typing in the chat?

For example if I press “/” and say “Hi Bill, how are you?” It would remove my helmet and then put it back on, seeing how there are two H’s in that sentence.
This is the code:

"local UIS = game:GetService(“UserInputService”)

UIS.InputBegan:Connect(function()
if UIS:IsKeyDown(Enum.KeyCode.H) then
game:GetService(“ReplicatedStorage”).RemoteEvent:FireServer()
end
end)"

It then fires the remote event and removes the player’s helmets and puts on their hats, or removes their hats and puts on their helmet.

Try this. InputBegan passes in two arguments: the input object and a boolean representing if stuff like chat has already processed the event.

local UIS = game:GetService("UserInputService");
local event = game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvent");

UIS.InputBegan:Connect(function(input, processed)
    if (input.KeyCode == Enum.KeyCode.H and processed == false) then
        event:FireServer();
    end
end);
1 Like

Thank you. I just had to rename the “RemoteEvent” to what I had renamed it before I posted this.