Should I Use OOP for my Flight and Combat Scripts?

I want to make a game that has classes that players can use. I’m learning about OOP and its implementation, and combining the power of metatables and module scripts for high-efficiency code. I want to migrate to using more advanced and efficient code structures, but I’m not sure if it’s possible and if it’s the best choice for my situation.

I have built a basic flight system using VectorForce, AlignOrientation and some animations, that I want to be able to reuse across multiple different classes by making it a module, but currently that flight script is a local script. This script is composed of functions that manipulate the VectorForce and AlignOrientation, both of which are stored inside the local script, as well as some functions that run animations based on velocity, and proximity to the ground. I like the way it works and looks, and would like to make it a module script so that I can re-use it with other animations in the future.

Similarly, I have a basic combat system that I want to be standard across all classes, and so I also want to make this script a module, but it’s also a local script. This script is just composed of handling a 5-attack basic attack string, so it loops through 5 different attack animations and then the server would handle the hitboxes and stuff like that.

What I’m stuck on is that from my perspective, I can either make this flight system and combat system a module that runs on the client, which makes it exploitable, or put them on the server, which makes it laggy, and I just don’t have the development and coding experience to know how to compromise between the two. I am asking for insight or learning resources that can help me figure out how to organize my code so that it’s clean, reusable, and I can build in some protections against exploiting.

I have looked through many devforum posts and youtube videos about these topics, including metatables, module scripts, server-client communication, and anti-exploit measures, and I haven’t been able to piece the information together into a usable solution. I just don’t know where to go from here. I believe that OOP is a good way to organize my project, so that it will be easy to grow into a full game in the future, but I don’t think I understand enough about it to know if I should use it here, and so I’m asking for help. I’ll provide extra information if needed or asked for.

1 Like

my combat has all animations on the client, and when they attack, it will send the input to the server, i think, as long the information is not too complex, the server will not explode and die,

about exploiters, create some counter where if they send any false info, they will get exploded perma banned, and only with some recording with proof, they may get unbanned

you can send some sort of info about which animation is playing on the client, send to the server
and, the server will check if X animation combines with Y Attack [Punch] for example,

( Server-sided module, you can create all combinations possible of attacks and patterns )
(Same for the Client, but client side is only for visuals and cool effects)


if they send Z animation but the server said:
Z animation is not compatible with Y, and this combinations doens’t exist on my module

the correct would be X and Y!

-he will get wiped out of existence and banned, that’s it, because, normal players cannot send false information by accident, only if you mess up your code very bad

logic is everything, and yea they will exploit their animations, whatever, you can make some script that checks their current animations ( oh boi ) and if they are playing certain animations that is totally ‘what the’ , then the server will ban them

just some idea, btw

Thank you for your response, this is essentially the approach I have right now. I’m sorry if it was unclear, but what I’m asking is how can I keep this sort of approach while possibly using module scripts to make it easier to reuse the basic code I’ve created. Your response helps me make code that has protection against exploiting, but I still need a way to make it clean and reusable, as I’ve said in the post.

You have two different issues at hand, the coding and exploiting. Exploiting will be an issue no matter where the scripts are. The majority of the players do not exploit, so I would personally prioritize on lag removal. OOP is usually very good, I use it a lot, maybe too much even, but it truly is a great tool for making things structured in a neat way.

I would make it into a module script on the client, any exploiting that script may lead to is exploiting you would more easily be able to catch on the server, since you would know exactly what it would look like.

Thank you for your response! In that case, I’m going to start trying to optimize my code and see how it goes from there. I’ll be sure to look into anti-exploit measures more, but are you referring to stuff like sanity-checks and things like that to “catch” it on the server?

Yes, that is exactly what I mean. Since you wrote the module you would have better insight to how its movements would work which might help with sanity checking.

1 Like

Ok so you should use OOP and become a cool lua nerd :nerd:

So this is why
1- It will improve your workflow and make interacting with game code so much easier
2- It embraces the dont repeat yourself rule so you dont constantly paste code that once you update or change you have to modify it in every place you also usedn it
3- Holy moly making objects is so cool, like fr, you can make anything and have an engine interact with them.

Use OOP dont listen to the voices from the OOP haters.
become an OOP user :nerd:

1 Like

Thank you for the response haha. I’m excited to see what kind of stuff I can make with it, I’ll definitely be learning more about it soon!