Help with modulescript keybinds

  1. What do you want to achieve? Im trying to make a cuff system, and I’m trying to make it so users can configure keybinds for open/close and other actions.

  2. What is the issue? I don’t think the key presses are registering or I’ve configured the module script wrong.

  3. What solutions have you tried so far?
    Devhub, youtube

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

Module script:

local settingsconfig = {}

settingsconfig.Groups = {
	[1111] = 123;
	[232323] = 123
}

settingsconfig.Keybind = {
	["open"] = Enum.KeyCode.K;
	["close"] = Enum.KeyCode.K;
	["arrest"] = Enum.KeyCode.E;
	["release"] = Enum.KeyCode.R;
	["search"] = Enum.KeyCode.S
	
}
return settingsconfig

LocalScript:

local userInputService = game:GetService("UserInputService")
local config = require(game.ReplicatedStorage.Config)

userInputService.InputBegan:Connect(function(input, GPE)
	if input.KeyCode == config.Keybind.open then
		print("Cuffs closed")
	elseif input.KeyCode == config.Keybind.close then
		print("Cuffs opened")
	
	end
end)

Pasting these exact scripts into a fresh baseplate works perfectly, as expected.

Also, your open and close keybinds are the same, is that the issue?

Yeah thinking that has to be the issue, if the keycode is K, the close one will never be called. This could still work, but you need to track whether it’s opened or closed already.

i.e.

local opened = false
userInputService.InputBegan:Connect(function(input, GPE)
	if input.KeyCode == config.Keybind.open and not opened then
		print("Cuffs opened")
        opened = true
	elseif input.KeyCode == config.Keybind.close then
		print("Cuffs closed")
        opened = false
	end
end)
2 Likes