How do you prevent ButtonPresses from registering when using the new Chat Box?

This is very old coding, and I’m not sure what broke this; but essentially.. if a certain letter like G is pressed.. it’ll open a UI. If the person is typing in the chatbox and hits G, it shouldn’t open the UI.

What broke in this coding when using the new chat system?

--[[Made By Just2Terrify]]
--/Variables\--
local UIS = game:GetService("UserInputService")
--/Functions\--
local function TweenTabControl()
	local Panel = script.Parent["Settings Frame"]
	local Button = script.Parent["Control Button"]
	local KeybindValue = script.KeybindValue.Value
	if Panel.Position == (UDim2.new(-1, 0, Panel.Position.Y.Scale, 0)) then
		spawn(function()Panel:TweenPosition(UDim2.new(0, 0, Panel.Position.Y.Scale, 0), 'In', 'Linear', 0.5) end)
		Button.Text = "CLOSE ".."["..KeybindValue.."]"
		Button.TextColor3 = Color3.fromRGB(255,255,255)
		Button.BackgroundColor3 = Color3.fromRGB(170,0,0)
	else 
		spawn(function()Panel:TweenPosition(UDim2.new(-1, 0, Panel.Position.Y.Scale, 0), 'In', 'Linear', 0.5) end)
		Button.Text = "Controls ".."["..KeybindValue.."]"
		Button.TextColor3 = Color3.fromRGB(0,0,0)
		Button.BackgroundColor3 = Color3.fromRGB(0, 170, 255)
	end
end

--/Main Script\--
UIS.InputBegan:Connect(function(KeyPressed)
	if UIS:GetFocusedTextBox() then
		return
	end
	
	local Key = Enum.KeyCode
	local KeybindValue = script.KeybindValue.Value
	if KeyPressed.KeyCode == Key[KeybindValue] then
		TweenTabControl()
	end
end)
2 Likes

Not sure how this changed, but if you’re looking for a fix here it is.

InputBegan passes an InputObject for the key press and a boolean for whether or not it was already processed. It should be an easy fix, just rewrite

UIS.InputBegan:Connect(function(KeyPressed)
	if UIS:GetFocusedTextBox() then
		return
	end
    --rest of code
end)

to

UIS.InputBegan:Connect(function(KeyPressed, gpe)
    if gpe then return end
    -- rest of code
end)
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.