So, I currently developing a fighting game. Where my fighting game has many different fighters to choose and each character has their unique skill for an attack.
I know how to use UserInputService, ContextActionService, Remote event, function, animation to make a combat system. I can easily create a single character that has different skills using a different button (since there are many youtube tutorials out there). But, the real challenge is that I have to make that the skill attack outcome depends on what fighter the player is choosing.
I can make a value that collects the fighter name, that player chooses. Then when the player presses the button, it checks on that value with if condition to see what function (that contains fighter skill) will fire. The problem is it will make a long line of code in a single local script, which I don’t think it’s a good practice to do and might cause a delay when it has to check through all the fighter name with many if condition when pressing a button.
So, I want to hear you guys recommend, what’s the best way to code a fighting game that it has many fighter and unique skill. Thanks in advance.
“It will make a long line of code in a single localscript.” And that’s where we get into modulescripts! I won’t explain them and I really do recommend reading the devforum explanation on it but in simplest terms; for code that you want to run multiple times in multiple scripts, you’ll use modulescripts for not only keeping your game neat but optimisation (as you wouldn’t want to past the same lines of code in several scripts).
You can create a function inside the modulescripts which returns the player’s fighter by utilising the inputted parameters from the script referencing it then store it inside a table within that modulescript for further use without needing to constantly check
Hmm, I guess it’s time to learn more stuff. I never use a module script before. Can you provide some line of code, on how your solution work plz. Thanks so much for recommending tho.