A coding dilemma which I have

So I am making a weapon system where I make every weapon goes through the same code when it comes to equipping, shooting (or swinging if the weapon is a melee) and when activating the ability in which activates a custom function that does the ability, no matter how much I accommodate for different types of weapons, I always need to adjust the core weapons script every time I make a new weapon to accommodate the cool ideas and features I have with it, and sometimes I cannot do that without major changes to my code, or make the specific weapon I am making separate from the main weapons script. And it doesn’t help that the system switches between different scripts so many times.

So what’s supposed to be a streamlined code that works with every weapon, now filled with constant detours checking is a weapon has this or that feature due to their differences and features and now I’m stuck with a dilemma.

Code every weapon individually and face repeating the same code 80% of the time.

or

Make an integrated code that accommodates for every weapon but faces bugs and constant detours in the code if I change stuff up in order to add a new weapon.

I’m sure there may be a third option which has the pros of both so if you have and suggestion or questions about my code, please let me know in the comments.

Definetly go for streamlined, if you animations and models add up it should make it as easy as copy paste, ofc with tweening swing speed damage and such, what problems exactly are you running into?

So I am making a unique ability which allows the player to place down a weapon that can shoot its enemies on its own. Currently when I activate any ability, it sends the request to the server to allow sound effects and the server-side of what the ability does, but the ability I am making directly requires doing parts of it in the client first before sending over the script into the server, as I am using a tutorial for it.

The code done in the tutorial isn’t compatible with the existing weapon system which I have so its quite hard to add a new weapon

Sounds like you’re right on track. Instead of checking the weapon, create a configuration folder in each and populate it with options for what the weapon can be and what it uses. Check the Roblox made weapons and look at how they put them together. They have a really nice all pro build.

Is it a gun? Try sending a remote event, the server then takes your gun away (assuming you want it to) and places it where you stand with a turret script, for normal use it just uses the streamlined code ie shooting aiming reloading etc.

It is a sentry gun that allows you to place it using an existing ‘weapon’ the player holds

I’m using this tutorial for its placement system (where the weapon has a button gui which allows it to ‘build’ sentries.

This is incompatible with the current requirement for sending the code to the server first from the client when the ability button is pressed

I see, you’ll have to make that unique then, I suppose you could make the server fire a callback (remote function) to the client and wait for a position, that would work

in your script when the button is pressed, it send a remote event to the server, server sees it’s this specific weapon so it sends a position request to the client in the form of a remote function, you listen for that on the client and it activate the placement mode, then when you click you return the position for placement to the server and the server places the sentry

isn’t server to client to server remote functions not recommended to use as if there is an error on the client, it yields the server?

Correct, but there’s no other way to facilitate client to server event and passing data later without a remote function that I know of, just add the necessary safeguards and it should be okay (idk all of them but it’s stuff like don’t allow any data type, also gotta keep in mind any code under it won’t run until it gets a response or you terminate it by force) Just gotta be more cautious with them since you give the client the ability to send data amd essentially pause the script, all preventable with checks, like using coroutines so it doesn’t stop the whole script or a time limit

alr but will errors in the client also break the server with coroutines

Honestly I’m not sure, I’d test it out and maybe look for a post or guide on how to use them correctly, but they exist for a reason, you want to use them in a way where not receiving a response or erroring won’t do anything to the whole script (first thing that comes to mind are coroutines because they run sepperately and you can terminate them easily for example if it waits for a response for too long so you don’t have too many running at once, or if one client tries to invoke it more than once with a script so it doesn’t lag the server)