How to create an abilities system using module scripts?

The keys module is only really there so that the server can know which key is bound to which magic move. The client can work that out because the UI itself is on the client.

My idea would be to bind the key to a remote which fires when the key is pressed. This would mean that since the magic move function data is on the server, the function can be executed on the server.

--CAS Function
Remote:FireServer(key.Value)

--Server
Remote.OnServerEvent:Connect(function(player, key)
 local MagicValid = require(player.MagicValid)
 Magic[MagicValid["MagicEquipped"][MagicValid["KeyBinds"][[MagicValid["MagicEquipped"]][key:Upper()](Player)

-- MagicValid
local MagicValid = {
	["MagicEquipped"] = "Fire",
	["KeyBinds"] = {
					["Fire"] = {
								"A" = "Breath Fire"
								},
					["Water"] = {
								"A" = "Typhoon Wall"
								}
					}
}
--You get the idea

If you did the UI set up on the client you would need to send a remote to the server to confirm the player’s MagicEquipped value.

Honestly, if the CAS example is too much effort you could just use UserInputService instead.

3 Likes

I’m starting to understand, but forgive me for the last few questions I might have: how can the client work that out, how is the UI related to that?

Well, you’re gonna have a localscript that’s gonna check if the key is pressed, and if it is, a remote event will be fired. I don’t think there’s UI in UserInputService, just pressing keys. In Context Action Service, you can add mobile compatibility easier, but I guess you aren’t close enough to release.

If you wanted clearer code you could actually access it from the client as well (since it’s in the player). My statement about the UI would be based on a naming and hierarchy system which is probably more confusing.

1 Like

I’d rather use CAS over UIS since it’s supposedly better btw. ^^"

Have you been able to find a solution yet?

So you are saying I should try naming the GUI buttons with the keys name (ex. ability triggered by pressing F > GUI button is named “F”)?

No, sadly ^^" It’s quite confusing. I’m really grateful for the help you guys have given to me so far though. I’ll try applying the method suggested by @PerilousPanther now.

I’ve started to get confused too. I think for now you should worry about the server-side and not the UI or it’s complexity.

Dumb question, but how is the value of MagicEquipped decided?

That would be dictated when the player chooses a magic. You’d want to store that kind of info on the server anyway, so it would probably be via a remote if you set everything up on the client.

Yes, but I realised that since the module is being stored in the player it can be accessed by the client and the server (but can only be changed by the server).

Honestly, I think it would be much more simple to understand and write if you used UserInputService, even if it is less performant (and it’s easy to switch between them) - although if you understand then obviously CAS is better for this use case. I definitely don’t think you should look at metatables at the moment as it would only add confusion.

1 Like

Sorry for the late answer, been a bit busy.
I wanted to say thanks to both @PandaLikesCaps and @PerilousPanther!
I ended up restarting the project and eventually figured out a method using UIS. You were a huge help nonetheless! :slight_smile:

1 Like

Glad you found out a way to do it!

1 Like