Keybinds, And Alternatives

So In the quickest manner possible. My issue is, on the client I want a player to press a button, 1-4 or the corresponding key binds, (which will be interchangeable).

local Keybinds = {
	["1"] = Enum.KeyCode.One,
	["2"] = Enum.KeyCode.Two,
	["3"] = Enum.KeyCode.Three,
	["4"] = Enum.KeyCode.Four,
}
local AlternativeKeybinds = {
	["5"] = Enum.KeyCode.One,
	["6"] = Enum.KeyCode.Two,
	["7"] = Enum.KeyCode.Three,
	["8"] = Enum.KeyCode.Four,
}

This is how it will be stored, In a table in the main client script.

How I want it to go is, when the player presses the button. If the button is found in the key binds table then it checks an unseen Boolean (Alt Move set) if it’s true, then it fires the alternative key binds index. Else, it’ll fire the normal key binds index into the server.

In an even shorter manner
Press button, check tables, if true, check if alt move set, fire pressed button index.

1 Like

For the sake of convenience I would switch the key and values of both table :slight_smile:

local serverevent = rep_Storage.Event
local uis = game.UserInputService
uis.InputBegan:Connect(function(i,p)
   if p then return end
   if Keybinds[i.KeyCode] then
       if AltMoveSet then
          serverevent:FireServer(AlternativeKeybinds[i.KeyCode])
       else
           serverevent:FireServer(Keybinds[i.KeyCode])
       end
   end
end)
2 Likes

Guys is this the most helpful dude on dev forum i see him everywhere??
Even though I did a bit of changing you helped in a sense

Final Working Code

uis.InputBegan:Connect(function(Input, GPE)
	if GPE then return end
	local Keys
	if AltMoveset then
		Keys = AlternativeKeybinds
		print("Using Alternative Keys")
	else
		Keys = Keybinds
		print("Using Normal Keys")
	end
	for i,v in pairs(Keys) do
		if Input.KeyCode == v then
				Ability:FireServer(i)
		end
	end
end)

Probably leaving the optimisation to you is better since I’m rubbish at it :wink:

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