当我在聊天时按“M”键时出现了我的GUI界面

好的,所以我有一个问题。我有一个Webhook报告GUI和脚本,按M键打开。但当我在输入时按M键,它会打开GUI。我该怎么解决?它的功能完美,只是在输入时按“M”键会打开GUI。

local key = Enum.KeyCode.M -- 如果需要,更改键
local gui = script.Parent.main -- 主框架
local plr = game.Players.LocalPlayer -- 获取本地玩家
local UIS = game:GetService("UserInputService") -- 获取服务

gui:TweenPosition(UDim2.new(0.382, 0, 1.229, 0))

UIS.InputBegan:Connect(function(Input)
    if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == key then --用户按键
        if gui.Position == UDim2.new(0.382, 0, 0.229, 0) then --如果打开
            gui:TweenPosition(UDim2.new(0.382, 0, 1.229, 0)) --关闭UI
        else --已关闭
            gui:TweenPosition(UDim2.new(0.382, 0, 0.229, 0)) --打开UI

        end
    end
end)

local sendbtn = script.Parent.main.send --- 发送按钮
local message = script.Parent.main.messageinput -- 消息框
local repstorage = game:WaitForChild("ReplicatedStorage")
local send = repstorage.reportevents.send
local sendcheck = false -- 防止发送按钮被刷屏多次
local cooldowntxt = script.Parent.main.cooldown
cooldowntxt.Visible = false
---- DISCORD WEBHOOK CONFIG IS IN SERVERSCRIPTSERVICE (report)

sendbtn.MouseButton1Click:Connect(function()
    if sendcheck == false then --检查是否最近已发送
        sendcheck = true
        send:FireServer(message.Text, sendcheck) --从客户端发送到服务器(serverscriptservice)
        sendbtn.Text = "Sent!" -- 自定义您想要的样式
        wait(0.7)-- 自定义您想要的样式
        sendbtn.Text = "A staff member will be with you soon!"-- 自定义您想要的样式
        wait(1.5)-- 自定义您想要的样式
        sendbtn.Text = "Send"-- 自定义您想要的样式
        cooldowntxt.Visible = true
        wait(70)-- 自定义您想要的样式
        sendcheck = false
        cooldowntxt.Visible = false
    end
end)

print("配置已加载")
点赞
用户2860267
用户2860267

UserInputService.InputBegan 信号 有一个名为 gameProcessedEvent 的第二个参数,它可以让你知道动作是否已经被游戏引擎内部处理过。

当你通常使用该动作时,gameProcessedEvent 将为 false,当你在聊天中输入时,它将为 true。你可以使用这个来决定何时显示你的菜单或不显示。

UIS.InputBegan:Connect(function(Input, gameProcessedEvent)
    -- 在用户正在聊天中输入时退出
    if gameProcessedEvent then
        return
    end

    if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == key then -- 用户按下键
        if gui.Position == UDim2.new(0.382, 0, 0.229, 0) then -- 如果已打开
            gui:TweenPosition(UDim2.new(0.382, 0, 1.229, 0)) -- 关闭 UI
        else -- 关闭状态
            gui:TweenPosition(UDim2.new(0.382, 0, 0.229, 0)) -- 打开 UI
        end
    end
end)
2021-05-21 00:52:46
用户16061697
用户16061697

检查当按下“m”键时,用户是否在输入(我知道你可以做到,但我不太确定如何实现)。

2021-05-29 16:32:58