What technique to use for a gun

I want to make a simple gun, a pistol, specifically, that simply works.

Problem is, there are many techniques on how to do one, and I simply can’t wrap my head around which one to choose, theres using a raycast, creating bullets using Instance.New and some other complex stuff, what should I use for the easiest, or atleast best results?

I’m checking the API, the devforums and youtube to see if I can find anything that I could do, the best outcome is that I find the absolute perfect way of creating a gun and I can use it as a base for making all the other guns, but I’m probably gonna have to settle something that’s out of my capacity, but still, I’m open to hearing suggestions.

I think RayCasts are the best to use. With it you can also perform checks on the server to make sure the client isn’t exploiting.

Saying that a gun should ‘simply work’ is rather vague for something that can be extremely simple, or something that can be extremely complex.

At the core of what a gun is, you can have a tool that when clicked it fires the Mouse.Target to the server, and if that happens to be a player, it deals damage.

This obviously is not what many people want when they say what a ‘gun’ is, because you see front-page games such as Phantom Forces with very complex guns. Here are some pointers for what Phantom Forces uses (atleast what I believe they use), and you can change that to fit yourself the best.

  • Custom viewmodel scripting that allows the first person perspective. This can be done using EgoMoose’s viewmodel tutorial here.
  • The idea that there is a clear separation between the visual representation and the function of the gun that you are using. In Phantom Forces, when you equip a sniper for example, the model is welded to the character for pure visuals. On the server, values are changed so that the server knows the player is shooting a sniper. These values include damage, firerate, ammunition, etc.
  • When it comes to the bullets themselves, this is a very complex field of programming that you can go as in depth as you feel like. Mapping projectiles has a lot of different ways that it can be approached, but Raycasts are the basics to it. But if you want to start adding things like recoil, spread, wall penetration, etc, you will have to do more research.

I hope this was helpful, if you have any further questions I’m free to help.

FastCast is a cool tool. It uses raycasting to create an efficient and lightweight gun engine, but it also simulates a real bullet going to its target as well, with added effects and stuff.

https://www.roblox.com/library/4453914752/FastCast-Redux-Example-Gun?Category=Models&SortType=Bestselling&SortAggregation=AllTime&SearchKeyword=FastCast&CreatorId=0&Page=1&Position=1&SearchId=bb54d229-4a74-4e2b-a515-bc77a35beb57

2 Likes

That’s another one I’ve encountered, that’s what I’m planning on using, but the bouncyness and gravity is a bit of an issue I still need to figure out how to use.

2 Likes