Can anyone tell me how to make disable scripts when a player is typing

So I have a couple of scripts on this game Crack A Cold One Simulator Remastered! - Roblox that rely on the key pressed events like if you press the key E or L. I want to detect if the player is typing and then disable them accordingly so they are not accidentally activated. How can I do this?

3 Likes

Hmm are you looking for GameProccessed?
It is a parameter that is passed in when Roblox detects the input and whether or not the input has already been detected or not for example typing in chat or clicked on a GuiButton.
This is how it would be used. UserInputService | Roblox Creator Documentation

-- In order to use the InputBegan event, the UserInputService service must be used
local UserInputService = game:GetService("UserInputService")
 
-- A sample function providing multiple usage cases for various types of user input
UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProccessed then return end -- Exit the function if the player is typing
	if input.UserInputType == Enum.UserInputType.Keyboard then
		local keyPressed = input.KeyCode
		print("A key is being pushed down! Key:",input.KeyCode)
	elseif input.UserInputType == Enum.UserInputType.MouseButton1 then
		print("The left mouse button has been pressed down at",input.Position)
	elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
		print("The right mouse button has been pressed down at",input.Position)
	elseif input.UserInputType == Enum.UserInputType.Touch then
		print("A touchscreen input has started at",input.Position)
	elseif input.UserInputType == Enum.UserInputType.Gamepad1 then
		print("A button is being pressed on a gamepad! Button:",input.KeyCode)
	end
end)
1 Like

Hmmm this is still confusing and I do not exactly know how to use this code maybe dumb it down for me haha?

This is the part that you might need. You can simply add this before the actual code that does whatever you want to do. Simply put it exits the function if the player is typing or if the player has clicked a gui button.

UserInputService.InputBegan:Connect(function(input, gameProcessed)-- Simply add the parameter here

so something like
if gameProccessed the return end
userinput.keycode blablabla --like this?

1 Like

but how can I differentiate between a player pressing the certain key and just typing?

That’s what GameProcessed does. If you’re typing in - say - a TextBox, the InputBegan will fire but GameProcessed will be true (I believe). So if the user isn’t typing anywhere (but still presses a key) it will be false

Ok thanks thats what i didnt understand so is this right?

uis.InputBegan:Connect(function(input, gameProccessedEvent)
if gameProccessedEvent then
	return
else
	if input.KeyCode == Enum.KeyCode.E then
		if cocaCola then
			if game.ReplicatedStorage.Values.ResetInProgress.Value == false then
				game.ReplicatedStorage.RemoteEvents.Drink:FireServer(player)
				    game.ReplicatedStorage.RemoteEvents.Drink.OnClientEvent:Connect(function(player, Argument)
					if Argument == "Play1" then
						animation2:Play()
						wait(.51)
						animation2.Stopped:Wait()
						animation:Play()
					elseif Argument == "Play2" then
						animation3:Play()
					elseif Argument == "Stop1" then
						wait(.31)
						animation:Stop()
					elseif Argument == "Stop2" then
						animation4:Play()
					end

				end)
			else

				return

			end
		end
	end
end

end)

Ahhh nevermind Got it to work thanks!