Disabling or Changing variable while chatting

for example, Disable press W to print something while chatting.
like

(local script)

local Chatting = false

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent) -- Key
	if inputObject.KeyCode == Enum.KeyCode.W and Chatting == false then
		print("W")
	end
end)

this situation.

you can use the second parameter itself
if it returns true then it means the player is typing

game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent) -- Key
	if inputObject.KeyCode == Enum.KeyCode.W and gameProcessedEvent == false then
		print("W")
	end
end)
1 Like

or if you really only want the chatbar

local ChatBar = game.Players.LocalPlayer:WaitForChild("PlayerGui").Chat.Frame.ChatBarParentFrame.Frame.BoxFrame.Frame.ChatBar
local Chatting = false

ChatBar.Focused:Connect(function()
	Chatting = true
	ChatBar.FocusLost:Wait()
	Chatting = false
end)


game:GetService("UserInputService").InputBegan:connect(function(inputObject, gameProcessedEvent) -- Key
	if inputObject.KeyCode == Enum.KeyCode.W and Chatting == false then
		print("W")
	end
end)

Getting the chatbar is too complicated Idk if there is a way to easily get it
you can try looping it if you want

1 Like
local UserInput = game:GetService("UserInputService")

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local ChatBar = PlayerGui:FindFirstDescendant("ChatBar")

local Chatting = false

ChatBar.Focused:Connect(function()
	Chatting = true
end)

ChatBar.FocusLost:Connect(function()
	Chatting = false
end)

UserInput.InputBegan:connect(function(Input, Processed)
	if Chatting then
		return
	end
	
	if Input.KeyCode == Enum.KeyCode.Backspace then
		print("Backspace key pressed!")
	end
end)