How would I use OOP for guns like these?

I’ve been learning things like RayCasting, OOP, UI, Animations and way more in order to learn how to create a gun system as my first advanced project. I’ve always used Roblox’s endorsed weapons kit and want to change.

I want my gun system to be HitScan though, so that the bullet automatically hits the player instead of using travel time (with bloom and recoil of course)

But I want some guns like snipers (I don’t know how shotguns work but I want them to do more damage the closer you are and idk if you need to disable hitscan for that or not) to use projectiles instead so there is a bullet speed. Do I create a seperate local script for weapons like these or is there a way to implement it in my Module Scripts?

You are going to have to create your own component system, and use CollectionService to tag your guns with ‘Gun’ and if it is a special type of gun then mark it with something else.

Then create a separate script called Gun (or your tag name) and do the things a normal gun should do (eg. shoot, reload, ADS) and with the special gun types, create a new tag for them and a module script for them too.

Here’s a great example of how you can create a component system (i used this to learn about OOP too!): https://www.youtube.com/watch?v=stJtnGGt-1c

1 Like

Thanks, I was also wondering how you would do things like crosshairs (I’ll only have about 3 so I think I can use modules and tags for them) but what about different animations, inspect animations, etc. do I program those in the gun tool and not the module (I feel like a good way to do this is use modules but have code that checks inside of the tool and do the specific animation in it but I’m not sure)

For different gun animations (e. g. inspect, reload, ads), You can create a function that handles the animation and needs the gun you are animating and the animationID. I haven’t really done much of this so I’m only helping you with the best of my knowledge. And for different crosshairs too.

I think a really easy way of doing this is having a module for every gun and it’s kind of like a settings module (e. g. reloadAnim, RPS, mag Size, etc.)

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.