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

Using Userinputservice but stuff doesn't work as planned?

I'm having a problem, I am using userinputservice to detect when a certain button on the keyboard is pressed, in that case the letter "g", when I press g, the script will play an animation on my humanoid, when I am writing in the chat ingame, and I put the letter "g" inside of the chat bar the animation is played I want to avoid that what should I do?

2 comments

0

There is a second argument which is passed which lets you know if the event was fired due to a gui.

1 answer

✓ Accepted answer

Basically, what you want to do is use this code:

--To put it simple, this blocks anything that is gameProcessed not interfere
--with your ungameprocessed UserInput. For example, the Roblox chat is gameProcessed.
--your UserInputService isn't, so what it's going to do if we didn't have if not gameProcessed
--this would make it where your userinput would be activated in gameProcessed situations. Like chat.
game:GetService("UserInputService").InputBegan:Connect(function(KeyDown, gameProcessed)
	if not gameProcessed then
		if KeyDown.KeyCode == Enum.KeyCode.G then
			--Do whatever you want it to do whenever someone presses, g. Or Holds g if you use the inputended event.
		end
	end
end)

game:GetService("UserInputService").InputEnded:Connect(function(KeyDown, gameProcessed)
	if not gameProcessed then
		if KeyDown.KeyCode == Enum.KeyCode.G then
			--Like I said earlier, if you want to hold g. if you don't, just use inputbegan.
		end
	end
end)

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