How do I make an editable keybinding system with my current system?

The goal is to change the KeyCodeKey in a ProximityPrompt to a keybind edited via gui.

The main premises of my current idea is that I have a gui where you can enter a keybind into (see below)

image
Highlighted in red can be changed to any key.

My idea to convert this string to a usable line of code was to use loadstring().

However, apparently I can’t use that as the error “loadstring() is not available” shows up.

image

Any ideas what I can do based on my current system? Or will I have to rework the entire thing?

You can do Enum.KeyCode[character] where character is a string like “E”. You will have to handle some keys specially though, since they have names that aren’t what they literally are. The 1 key is Enum.KeyCode.One for example.

Loadstring is off by default but can be turned on, I think in ServerScriptService. I strongly advise you don’t do this though, it creates a really dangerous security hole since someone can write any lua script into the keybind text box and it will run it. Making that system safe requires knowing a lot about how Lua works under the hood.

1 Like

Works a dream! Thanks for the advice on loadstring btw.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.