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

How do you make key inputs not detected when you're typing in chat?

So, basically I made a GUI that pops up whenever you press "B", but the issue I'm having is that whenever players are typing in chat the GUI pops up and gets in the way of everything. If someone could please tell me how to fix this it'd really be appreciated. Here is the code to pop up the GUI.

(Local Script)

local textBox = script.Parent
local originalColor = textBox.BackgroundColor3
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local screenGUI = script.Parent.Parent.Parent

if player:GetRankInGroup(5365673) >= 250 then
	print("literally nothing")
else
	script.Parent.Parent.Parent:Destroy()
end





UserInputService.InputBegan:connect(function(key)
    if key.KeyCode == Enum.KeyCode.B then
        if player:GetRankInGroup(5365673) >= 250 then 
		if screenGUI.Enabled == false then
			screenGUI.Enabled = true
			textBox.Active = true
			textBox.TextEditable = true
			script.Parent.Parent.TextButton.Visible = true
		end
		end
    end
end)





local function onFocusLost(enterPressed)
	if enterPressed then
		local plrText = textBox.Text
		print("The player typed: " .. textBox.Text)
		-- Color the text box according to the typed color
		local brickColor = BrickColor.new(textBox.Text)
		textBox.BackgroundColor3 = brickColor.Color
		game:GetService("ReplicatedStorage").Announce:FireServer(plrText,player)
		wait(1)
		textBox.BackgroundColor3 = originalColor
	end
end
textBox.FocusLost:Connect(onFocusLost)

1 comment

0

You can use ContextActionService.

1 answer

✓ Accepted answer

You can achieve this by the GameProcessed Boolean parameter returned by UserInputService’s InputBegan signal. This parameter defines whether one of ROBLOX’s core services is using input systems. You can debounce your code with GameProcessed to ignore your input events if so.

local UserInputService = game:GetService("UserInputService")

UserInoutService.InputBegan:Connect(function(Input, GameProcessed)
    if (GameProcessed) then return end
    if (Input.KeyCode == Enum.KeyCode.B) then
        --// Code
    end
end)

2 comments

0

agreed

0

That worked, thank you.

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