Help with equipping moves

hello everyone! So I want to make a game where you can have moves (special abilities) that you can equip and assign it to a key, but I’m kinda lost, I have no idea on how to make it so when you equip a move you can choose the keybind and whenever you press it, it fires the move, I js need an idea on how to make this system. Thanks

1 Like

For rebinding keys, take a look at the context action service class. To keep things sorted, I’d use object oriented programming to keep things organized and open up avenues to reuse code.

Let’s say you have a settings GUI, and the player sets a keybind. Like what @SourLemon100000 said, you can add a module script (you can put it in StarterPlayer > StarterCharacterScripts or wherever is most accessible) that just has keybind variables that scripts can use.

For example (the scripts I use were all placed under StarterCharacterScripts):

-- MODULE
local module = {}
module.KeyBindA = Enum.KeyCode.X

return module

-- SCRIPT A
local module = require(script.Parent.ModuleScript)

warn(module.KeyBindA) -- Enum.KeyCode.X
module.KeyBindA = Enum.KeyCode.Y

-- SCRIPT B (ASSUMING THIS RUNS AFTER SCRIPT A)
local module = require(script.Parent.ModuleScript)

warn(module.KeyBindA) -- Enum.KeyCode.Y

As for registering inputs, I suggest using either ContextActionService (like @SourLemon100000) or UserInputService

Example of using UserInputService alongside the module:

local UIS = game:GetService("UserInputService")

local module = require(script.Parent.ModuleScript)

UIS.InputBegan:Connect(function(input, isTyping)
	if isTyping then
		return -- dont run code if chat is open / player is chatting
	end
	
	if input.KeyCode == module.KeyBindA then
		warn("DO SOMETHING!!!")
	end
end)

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