I am trying to script a Gui with a keybind menu, and the way I swap out keybinds is by checking if a player clicks a specific TextLabel, then finding their next input with UIS.InputBegan:Wait(). However, the issue here is that I have no idea what this input could be, and I don’t want it to cause the player to do an attack in the real game. For example, if I was to set Attack2 to the R key, Attack2 would play the second the key is bound, and I don’t want this.
To make my question a bit clearer, how would I make a system that would find and ‘invalidate’ any key the player presses, so they can’t trigger any in-game InputBegan/BindAction events?
Here is my function that handles all of this, which fires when a player clicks on a TextLabel that corresponds to a keybind
local function changeKeybind(textbox, action)
if debounce then return end
debounce = true
clickysound:Play()
local prevtext = textbox.Text
textbox.Text = "WAITING FOR INPUT"
task.wait()
local input = UIS.InputBegan:Wait()
local override = nil
local overridename = nil
while input.KeyCode.Name == "Unknown" do --override to deal w/ m1 and m2
if input.UserInputType.Name == "MouseMovement" then
task.wait()
input = UIS.InputBegan:Wait()
else
override = input.UserInputType
overridename = override.Name
break
end
end
for _, bad in pairs(badkeys) do --keys that player isn't allowed to use
if bad == input.KeyCode then
textbox.Text = "INVALID INPUT"
task.wait(0.5)
textbox.Text = prevtext
controls:Enable()
camera.CameraType = Enum.CameraType.Custom
debounce = false
return
end
end
for name, v in pairs(keybinds) do --if another key bound to given keycode, unbind that attack's key
if name ~= textbox.Parent.Name and override == v or input.KeyCode == v then
textbox.Text = "Unbinding "..tostring(name)
task.wait(0.5)
keybinds[name] = "Unbound"
menu.KeybindsPage.Keybinds[name].Key.Text = "Unbound"
break
end
end
--these lines aren't really important, just saving results of keybind swap
keybinds[textbox.Parent.Name] = override or input.KeyCode
textbox.Text = overridename or input.KeyCode.Name
updateControls:Fire(keybinds)
debounce = false
end