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

How do you make key inputs not detected when you're typing in chat?

Asked by
Pejoume 11
4 years ago
Edited by Ziffixture 4 years ago

So, basically I made a GUI that pops up whenever you press "B", but the issue I'm having is that whenever players are typing in chat the GUI pops up and gets in the way of everything. If someone could please tell me how to fix this it'd really be appreciated. Here is the code to pop up the GUI.

(Local Script)

local textBox = script.Parent
local originalColor = textBox.BackgroundColor3
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local screenGUI = script.Parent.Parent.Parent

if player:GetRankInGroup(5365673) >= 250 then
    print("literally nothing")
else
    script.Parent.Parent.Parent:Destroy()
end





UserInputService.InputBegan:connect(function(key)
    if key.KeyCode == Enum.KeyCode.B then
        if player:GetRankInGroup(5365673) >= 250 then 
        if screenGUI.Enabled == false then
            screenGUI.Enabled = true
            textBox.Active = true
            textBox.TextEditable = true
            script.Parent.Parent.TextButton.Visible = true
        end
        end
    end
end)





local function onFocusLost(enterPressed)
    if enterPressed then
        local plrText = textBox.Text
        print("The player typed: " .. textBox.Text)
        -- Color the text box according to the typed color
        local brickColor = BrickColor.new(textBox.Text)
        textBox.BackgroundColor3 = brickColor.Color
        game:GetService("ReplicatedStorage").Announce:FireServer(plrText,player)
        wait(1)
        textBox.BackgroundColor3 = originalColor
    end
end
textBox.FocusLost:Connect(onFocusLost)

0
You can use ContextActionService. niroqeo 123 — 4y

1 answer

Log in to vote
1
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

You can achieve this by the GameProcessed Boolean parameter returned by UserInputService’s InputBegan signal. This parameter defines whether one of ROBLOX’s core services is using input systems. You can debounce your code with GameProcessed to ignore your input events if so.

local UserInputService = game:GetService("UserInputService")

UserInoutService.InputBegan:Connect(function(Input, GameProcessed)
    if (GameProcessed) then return end
    if (Input.KeyCode == Enum.KeyCode.B) then
        --// Code
    end
end)
0
agreed HappyTimIsHim 652 — 4y
0
That worked, thank you. Pejoume 11 — 4y
Ad

Answer this question