Efficient way to implement client side Keybind loading?

So I was wondering what would be the best/most efficient way to really implement Keybinds that are editable by the player however I am asking more on the side of loading/handling them.

I can save them and have a few ideas in place on how I want too but that isnt important to include here.

There is no specific methods, it is nothing else than some additional values to save into the datastore.

You can use StringValues for PC keybinds so you can do that when detecting input:

if Enum.KeyCode[Keybind.Value] then

Or you can use a unique ID’s for each possible keybinds (pc and console), then do a dictionnary with a ID = enum.Keybind then when detecting input do that:

local Keybinds = {
    Id = Enum.Keycode.A;
    Id = Enum.Keycode.B
}

if Enum.KeyCode == Keybinds[Id.Value] then
2 Likes

Not what I was asking really. All I wanted was a method/structure for how to really structure the system e.g:

Module script → loads settings into table → client can access (read/write) → player leaves → saves


I dont want code not what I am asking.

2 Likes

Personally, the way I handle my implementations is that there can be any number of inputs associated with a single “action”, so I would store them in a dictionary in the datastore if I wanted it to be saved (cause I haven’t gotten around to doing that yet), with the format for one being something like:

Settings  = {
    Keybindings = {
        WeaponPrimaryAttack = {
            "ButtonR1",
            "MouseButton1"
        }
    }
}

Where the strings are converted to their corresponding Enum values with a lookup table.

3 Likes

More on what I was looking for.

I have made a wip system (code wont be great or anything nor have I tested it yet) which I can provide below if you would like.

1 Like

I’m glad to have been helpful. If you want someone to review your code, you can post it to #help-and-feedback:code-review.

3 Likes