#Keybind Listening and It's cancellation

3 messages · Page 1 of 1 (latest)

glacial talon
#

I have a button called ActionBIND
The thing I want to do is

local Listening = false
local SelectedKey = nil
ActionBIND.MouseButton1Click:Connect(
    function()
        if not Listening then
            Listening = true
            local Input
            repeat
                Input = game:GetService("UserInputService").InputBegan:Wait()
            until Input.UserInputType == Enum.UserInputType.Keyboard or
                Input.UserInputType == Enum.UserInputType.MouseButton1 or
                Input.UserInputType == Enum.UserInputType.MouseButton2
            do
            end
            SelectedKey = Input.KeyCode ~= Enum.KeyCode.Unknown and Input.KeyCode or Input.UserInputType
            Listening = false
            print(SelectedKey)
        else
            Listening = false
        end
    end
)

What I want to do is
When I click the button its listening for an input, it can be any keycode or MouseButtons
But. the issue is
When I'm listening for an input and I click the button again it registers the Input and starts listening again
How would I make it so when Im listening for an input and I click the button again It wont register the MouseButton1 and will print "Listening cancelled"

median pollen
#

Right?