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

User Imput Service works in chat too?

Hello, I am doing a Difficulty Chart obby and I added a "Press R to reset" function, but the character resets even if pressing "R" while typing in the chat.

Here's the script:

local uis = game:GetService("UserInputService")
local character = script.Parent
local reset = false
local humanoid = character:WaitForChild("Humanoid")

uis.InputBegan:Connect(function(key)
	if key.KeyCode == Enum.KeyCode.R then
		reset = true
		humanoid.Health = 0
	else
		reset = false
	end
end)

I would the function to only work when not in the chat, as it is annoying.

1 comment

0

If my below answer is helpful please mark it as answered

1 answer

✓ Accepted answer

You can use the gameprocess parameter to disable this because the chat is technically a gui read it here:

https://devforum.roblox.com/t/how-to-disable-userinputservice-while-chatting-typing-etc/495326

this parameter checks if your input is in a gui or not

The script:

local uis = game:GetService("UserInputService")
local character = script.Parent
local reset = false
local humanoid = character:WaitForChild("Humanoid")

uis.InputBegan:Connect(function(key, gameprocess)
    if not gameprocess then
      if key.KeyCode == Enum.KeyCode.R then
         reset = true
         humanoid.Health = 0
    else
        reset = false
    end
end)

7 comments

0

you added two else in your code, which will result in an error

0

other than that this will work, also, contextactionservice will work as alternative

0

@JesseSong but 1 else if for if not gameproces..... and the 2nd else is for if key.KeyCode......

0

That wouldn't work.  If statements only require one else, end, inside of its scope, like many other programming languages.

0

i think you meant elseif?

0

Why does a moderator keep saying that my answer does not fully answer the question?

0

ok i have edited my code @JesseSong thanks!

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