Block activation of a button when typing in chat

I am trying to block the activation of a key when I am typing in chat but it does not work, what am I doing wrong?

local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
local remote = game.ReplicatedStorage:WaitForChild("granada")
local upgradeStuff = game.ReplicatedStorage.HEGrenade 
local quantity = game.StarterPlayer.StarterCharacterScripts.intvalues.IntValue1
local Mouse = Player:GetMouse()
local userInputService = game:GetService("UserInputService")
	


game:GetService("UserInputService").InputBegan:Connect(function(iobj, gameprocess)
	
	
	if not gameprocess then
		if iobj.KeyCode == Enum.KeyCode.G then
			if quantity.Value >= 1 then
				
				
			remote:FireServer()
			quantity.Value = quantity.Value -1
			PlayerGui.BackpackGui.Frame.Frame.Equip.LocalScripte.Disabled = true
			PlayerGui.BackpackGui.Enabled = false		
			script.Disabled = true
			wait(2)
			PlayerGui.BackpackGui.Enabled = true
			PlayerGui.BackpackGui.Frame.Frame.Equip.LocalScripte.Disabled = false
			wait(10)
				script.Disabled = false
			end
		
			end
		end
		end)
1 Like

oh no that’s just the name of a script

before typing “if not gameprocess then” it works perfectly

when activating the g key it also recognizes it as a “gameprocess” that’s why it doesn’t work

How can this be

local quantity = game.StarterPlayer.StarterCharacterScripts.intvalues.IntValue1

If you put something in StarterPlayer.StarterCharacterScripts, it will be inside character

It should be like this

local quantity = Player.Character.intvalues.IntValue1

1 Like

The following code based off of yours works fine for me. I’d suggest fixing the indentation in your script to make it easier to read.

local Player = game.Players.LocalPlayer
local PlayerGui = Player.PlayerGui
--local remote = game.ReplicatedStorage:WaitForChild("granada")
--local upgradeStuff = game.ReplicatedStorage.HEGrenade 
local quantity = game.StarterPlayer.StarterCharacterScripts.intvalues.IntValue1
local Mouse = Player:GetMouse()
local userInputService = game:GetService("UserInputService")
game:GetService("UserInputService").InputBegan:Connect(function(iobj, gameprocess)
	if not gameprocess then
		if iobj.KeyCode == Enum.KeyCode.G then
			if quantity.Value >= 1 then
				print("works")
			end
		end
	end
end)

“works” does not print in output when pressing G if typing in chat.
Can you explain what exactly does not work for you? Is an error printed, does it fire the event even when chatting?

Help requests do not belong in Code Review. I have recategorised this to Scripting Support. Please review category guidelines and look for other categories that might be more suitable before posting threads.

1 Like