Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

User Imput Service works in chat too?

Asked by
TudiPYM 12
3 years ago

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.

0
If my below answer is helpful please mark it as answered sne_123456 439 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

When answering, if your answer does not fully solve the question, it should be written as a comment to the question instead of as an 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)

0
you added two else in your code, which will result in an error JesseSong 3916 — 3y
0
other than that this will work, also, contextactionservice will work as alternative JesseSong 3916 — 3y
0
@JesseSong but 1 else if for if not gameproces..... and the 2nd else is for if key.KeyCode...... sne_123456 439 — 3y
0
That wouldn't work.  If statements only require one else, end, inside of its scope, like many other programming languages. JesseSong 3916 — 3y
View all comments (3 more)
0
i think you meant elseif? JesseSong 3916 — 3y
0
Why does a moderator keep saying that my answer does not fully answer the question? sne_123456 439 — 3y
0
ok i have edited my code @JesseSong thanks! sne_123456 439 — 3y
Ad

Answer this question