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

How do I detect the users input then stop detecting it?

Asked by 4 years ago

I am creating a shop gui that will open and close when the players chosen key is pressed. I found out how to find the key, but not stop detecting the key after a key is pressed for the first time. Heres my code:

but = script.Parent
local UIS = game:GetService("UserInputService")
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local function inputDetecter()
    repeat UIS.InputBegan:Connect(function(key, gp)
        print(key.KeyCode)
        but.KeyVal = tostring(key.KeyCode)
    end)
    until mouse.KeyDown
end


but.MouseButton1Click:Connect(function()
    inputDetecter()
end)

1 answer

Log in to vote
0
Answered by
St_vnC 330 Moderation Voter
4 years ago

If you want to detect when the player releases a key then try

UIS.InputEnded:Connect(function(key, gp)
    print(key.KeyCode.. " was released!")
end)
Ad

Answer this question