Userinputservice using custom key

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    Well I’m wondering if it’s possible to make a custom keybind sort of thing, if the player choose F to be the key or if the Player choose R to be the key, is this possible?
  2. What is the issue? Include screenshots / videos if possible!
    I don’t know where to start, as I’ve tried to figure out how to make it or how to go about it, I’ve done alot of searching but I can’t find anything relating to it
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    Yeah I’ve looked for solutions on the Hub and also on the Web but I haven’t be lucky enough to find a solution

This could work.

local uis = game:GetService("UserInputService");

script.Parent.MouseButton1Click:Connect(function() -- the player presses a button to change the keybind/initiate it
uis.InputBegan:Connect(function(key)
-- do whatever you want with key.KeyCode
end)
end)

Going off of what @ScriptedSuper said, you could simply contain a variable for each bind, such as

Zoom = Enum.KeyCode.Q

and allow the user the manipulate that value, probably through some UI menu. From there, using the Input Began function you can check if the key = Zoom

Zoom = Enum.KeyCode.Q

local uis = game:GetService("UserInputService");

script.Parent.MouseButton1Click:Connect(function() 
    uis.InputBegan:Connect(function(key)
        if key.KeyCode = Zoom then
            --Action
        end
    end)
end)

Hmm but is their a way for the player to set it, like maybe on a text box or something, they enter let’s say R, into the box and it’s set for that key

if key.KeyCode.Name == TextBoxText then

That could work, as the player would set the key inside the box, and when it’s retrieved the key should still be there in the box right ?

local userInput = game:GetService("UserInputService")

local textbox = script.Parent

userInput.InputBegan:Connect(function(input, processed)
	if processed then return end
	
	local success, result = pcall(function()
		return Enum.KeyCode[textbox.Text]
	end)
	
	if success then
		if result then
			if input.KeyCode == result then
				print("Hello world!")
			end
		end
	end
end)

Should be relatively simple to implement this.

image