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.
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.
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.
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.
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!