How would I go about making this skill / selection system?

Hey there! I want to make a skill system, where there are set keys (E R T Z X C), and you can set keybinds to them. For example, when you press a button / key, a UI will open. In said UI, there will be a list of your skills. You would click on a skill then click on the key.

This would be considered similar to Jujutsu Chronicles’ system.

For reference:

Icon that show the skills and the keys they are assigned
image

A UI that lets you bind skills to keys

Thank you for your time.

1 Like

For keybinds you can do

game:GetService("UserInputService").InputBegan:Connect(input)
if input.KeyCode  == Enum.KeyCode.F then
etc...
1 Like

You would want to use something like UIS or CAS (UserInputService, ContextActionService) to bind each button, and once the button is pressed, fetch the corresponding ability that the player has equipped. What I would do is assign each ability to a number (Z = 1, X = 2, C = 3, ETC), and once the code detects a key is pressed, first check if its one of the skill keys. If it is a skill key, check which skill is attached to said key (I would use a table held inside of a string value to store this data), and if they have it equipped then have a module with all the abilities client code, and run the data there. ALWAYS MAKE SURE TO DOUBLE CHECK IF THEY CAN USE THE ABILITY ON THE SERVER

1 Like

use UIS to check if the inputs that the user makes are the keys that you are looking for in the UI
you can also use UIS to know what key the user wants to bind that skill to

local uis = game:GetService("UserInputService")

local skillKey1

uis.InputBegan:Connect(function(inpObj, processed)
  if isSelectingKey then
    skillKey1 = inpObj.KeyCode
  elseif inpObj.KeyCode == skillKey1 then
    -- do skill
  end
end)

Thank you, you have given me an idea. So I would have a table set in the character like this:

{
["E"] = "FireJab",
["R"] = "FlameRotation",
["T"] = "Jet Propulsion",
["Z"] = nil,
["X"] = nil,
["C"] = "Fire Wall",
}

And it would be stored in a datastore. Each time the player updates it, it will be saved to the datastore again, as well as when the player leaves the game.

better to use Enum.KeyCode.X as the key instead of a string

Here is my idea.

A Local script that will fire a remote event / remote function for each key. For example

if input.KeyCode == Enum.KeyCode.E then
      ability1:FireServer()-- or InvokeServer()
end
``

A server script that will listen for the remote, and it will send back cooldown and fx.

```lua
function remote(ability1 : RemoteEvent)
	ability1.OnServerEvent:Connect(function(player)
		local moveset = player:FindFirstChild("Moveset")
		local abilityName = moveset["E"]
	end)
end

but why wouldn’t you just do

game:GetService("UserInputService").InputBegan:Connect(input)
abilityName = moveset[input]

where the keys are the Enum.KeyCode instead of a string

Because the moveset is handled on the server, the client is just sending the information, unless I am misunderstanding?

If you use a string such as [“E”], you have to have code which says

if input == Enum.KeyCode.E then ... :FireServer("E")
elseif input == Enum.KeyCode.F then .. :FireServer("E")

( That’s not exactly how you have it written but it’s close enough in concept.)

Instead you could just do

:FireServer(input)

and using that to handle things on the server. It just makes your code more efficient.

Well the way i work is with instances, but for your case youd want to do something as follows

local abilities = { -- This will be relative to what the player has equipped
  Enum.KeyCode.E.Value = "FireJab",
  Enum.KeyCode.R.Value = "FlameRotation" --etc
}

local abilitiesModule = require(game:GetService("ReplicatedStorage").Abilities --abiities module where all the client code is stored for the abilities

game:GetService("UserInputSerivce").InputBegan:Connect(function(input, gpe)
   if gpe then return end --basic uis stuff
   
   if abilities[input.KeyCode.Value] then --if the key pressed matches an entry inside of the table
      abilitiesModule[abilities[input.KeyCode.Value]]() --Finds the function inside of the abilities module with the exact name as the one inside of the table that is assigned to the key
   end
end)

Very simplistic design, all you do is put the name of the functions inside of the table, assign it to a keybind, and once an input is detected, check if the input is listed in the table, if it is then search a module for the corresponding function and run it.

I did not see this! Okay so making sure that I understand, I would turn E,R,T,Z,X,C into 1,2,3,4,5,6. When the client fires the remote for said key, loop through a table to find out which key is there, and run it. So I assume that for swapping / changing skills for keys, I would have to make a UI with buttons for each key, and UIGridLayout for all the skills, and when a skill is pressed then the key is pressed, it will fire to the server and the server will do the switching and the logic, correct?

Okay so I think I might have confused you. So the table of strings like “E” and “R” etc, are for the server and client. It is showing their current skillset/ loadout. I don’t send any information to the server right now

Is KeyCode.Value not a number? I saw you were assigning it a string

But in all, I think we have gotten off topic from my perspective. I am not saying that these have not been helpful, I have not scripted the skills yet. I am trying to make some “dummy skills” to test switching and casting. My original problem was that I had no clue on how to switch an item.

Let’s say the user had Earth wall set to E, but they wanted to switch it with Earthquake. How would I do that?