I’m trying to make an inventory GUI option.
When the E key is held for 3 seconds it makes the GUI visible to true
and when clicked again normally, it makes visible to false.
I don’t understand how to classify the e key clicked function.
can someone pls help?
local Gui = --your gui
UIS.InputBegan:Connect(function(input, Chat)
if not Chat then
if input.KeyCode == Enum.KeyCode.E then
if Gui.Enabled == true then
Gui.Enabled = false
else
Gui.Enabled = true
end
end
end
end)
local UIS = game:GetService("UserInputService")
local GuiObj = GUI_HERE
UIS.InputBegan:Connect(function(Key)
if Key.keyCode == Enum.KeyCode.E then
GuiObj.Visible = not GuiObj.Visible
end
end)
So you would need to define UIS then define your GUI (wherever it is).
Then I would use input.KeyCode == Enum.KeyCode.(Your key)
Then make the GUI enabled.
Else, you would make it disabled.
You can just use UserInputService to do that.
This script may not work or work incorrectly.
local GUI = nil--replace nil with the path to your gui
local KeyHolding = false
function fakewait(num)
if KeyHolding == true then
wait(num)
end
end
function Hold()
coroutine.wrap(function()
fakewait(3)
if KeyHolding == true then
GUI.Enabled = true
else
GUI.Enabled = false
end
end)()
end
local UIS = game:GetService("UserInputService")
UIS.InputBegan:Connect(function(io,gpe)
if gpe then return end
if io.KeyCode == Enum.Keycode.E then
KeyHolding = true
Hold()
end
end
end)
UIS.InputEnded:Connect(function()
if io.KeyCode == Enum.KeyCode.E then
KeyHolding = false
end
end)
This code makes a script run in a coroutine.
If key “e” is held, KeyHolding is set to true.
If not, it will be set to false.
It’s not in a loop.
After 3 seconds, it will check the value.
If it’s set to true, the gui will appear.
If not, it will not.
Have a nice day.