当我在聊天中输入 "M" 时,我的 GUI 会弹出
My GUI pops up when I press "M" while typing in chat
好的,我有一个问题。我得到了一个 Webhook 报告图形用户界面和脚本,可以通过按 M 键打开。但是,当我在键入时按 M 时,它会打开 GUI。我该如何解决这个问题?即使我正在打字,它也可以完美地打开 GUI 的“M”键。
local key = Enum.KeyCode.M -- Change the key if you want.
local gui = script.Parent.main -- Main frame
local plr = game.Players.LocalPlayer -- get local player
local UIS = game:GetService("UserInputService") -- get service
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 --User pressed key
if gui.Position == UDim2.new(0.382, 0, 0.229, 0) then --If open
gui:TweenPosition(UDim2.new(0.382, 0, 1.229, 0)) --Close UI
else --Is closed
gui:TweenPosition(UDim2.new(0.382, 0, 0.229, 0)) --Open UI
end
end
end)
local sendbtn = script.Parent.main.send --- send button
local message = script.Parent.main.messageinput -- message box
local repstorage = game:WaitForChild("ReplicatedStorage")
local send = repstorage.reportevents.send
local sendcheck = false -- stop spam of the send button
local cooldowntxt = script.Parent.main.cooldown
cooldowntxt.Visible = false
---- DISCORD WEBHOOK CONFIG IS IN SERVERSCRIPTSERVICE (report)
sendbtn.MouseButton1Click:Connect(function()
if sendcheck == false then -- checks if it was sent recently
sendcheck = true
send:FireServer(message.Text, sendcheck) -- sends it to server from client (serverscriptservice)
sendbtn.Text = "Sent!" -- Customize if you want
wait(0.7)-- Customize if you want
sendbtn.Text = "A staff member will be with you soon!"-- Customize if you want
wait(1.5)-- Customize if you want
sendbtn.Text = "Send"-- Customize if you want
cooldowntxt.Visible = true
wait(70)-- Customize if you want
sendcheck = false
cooldowntxt.Visible = false
end
end)
print("Config loaded")
UserInputService.InputBegan signal 有一个名为 gameProcessedEvent
的第二个参数,让您知道游戏引擎是否已在内部处理该动作。
当您正常使用操作时 gameProcessedEvent
将是 false
,而当您在聊天中输入时它将是 true
。您可以使用它来决定何时显示您的菜单。
UIS.InputBegan:Connect(function(Input, gameProcessedEvent)
-- escape if the user is typing in chat
if gameProcessedEvent then
return
end
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == key then --User pressed key
if gui.Position == UDim2.new(0.382, 0, 0.229, 0) then --If open
gui:TweenPosition(UDim2.new(0.382, 0, 1.229, 0)) --Close UI
else --Is closed
gui:TweenPosition(UDim2.new(0.382, 0, 0.229, 0)) --Open UI
end
end
end)
检查用户在按下 m 键时是否正在输入(我知道你可以做到,只是不知道该怎么做)
好的,我有一个问题。我得到了一个 Webhook 报告图形用户界面和脚本,可以通过按 M 键打开。但是,当我在键入时按 M 时,它会打开 GUI。我该如何解决这个问题?即使我正在打字,它也可以完美地打开 GUI 的“M”键。
local key = Enum.KeyCode.M -- Change the key if you want.
local gui = script.Parent.main -- Main frame
local plr = game.Players.LocalPlayer -- get local player
local UIS = game:GetService("UserInputService") -- get service
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 --User pressed key
if gui.Position == UDim2.new(0.382, 0, 0.229, 0) then --If open
gui:TweenPosition(UDim2.new(0.382, 0, 1.229, 0)) --Close UI
else --Is closed
gui:TweenPosition(UDim2.new(0.382, 0, 0.229, 0)) --Open UI
end
end
end)
local sendbtn = script.Parent.main.send --- send button
local message = script.Parent.main.messageinput -- message box
local repstorage = game:WaitForChild("ReplicatedStorage")
local send = repstorage.reportevents.send
local sendcheck = false -- stop spam of the send button
local cooldowntxt = script.Parent.main.cooldown
cooldowntxt.Visible = false
---- DISCORD WEBHOOK CONFIG IS IN SERVERSCRIPTSERVICE (report)
sendbtn.MouseButton1Click:Connect(function()
if sendcheck == false then -- checks if it was sent recently
sendcheck = true
send:FireServer(message.Text, sendcheck) -- sends it to server from client (serverscriptservice)
sendbtn.Text = "Sent!" -- Customize if you want
wait(0.7)-- Customize if you want
sendbtn.Text = "A staff member will be with you soon!"-- Customize if you want
wait(1.5)-- Customize if you want
sendbtn.Text = "Send"-- Customize if you want
cooldowntxt.Visible = true
wait(70)-- Customize if you want
sendcheck = false
cooldowntxt.Visible = false
end
end)
print("Config loaded")
UserInputService.InputBegan signal 有一个名为 gameProcessedEvent
的第二个参数,让您知道游戏引擎是否已在内部处理该动作。
当您正常使用操作时 gameProcessedEvent
将是 false
,而当您在聊天中输入时它将是 true
。您可以使用它来决定何时显示您的菜单。
UIS.InputBegan:Connect(function(Input, gameProcessedEvent)
-- escape if the user is typing in chat
if gameProcessedEvent then
return
end
if Input.UserInputType == Enum.UserInputType.Keyboard and Input.KeyCode == key then --User pressed key
if gui.Position == UDim2.new(0.382, 0, 0.229, 0) then --If open
gui:TweenPosition(UDim2.new(0.382, 0, 1.229, 0)) --Close UI
else --Is closed
gui:TweenPosition(UDim2.new(0.382, 0, 0.229, 0)) --Open UI
end
end
end)
检查用户在按下 m 键时是否正在输入(我知道你可以做到,只是不知道该怎么做)