Tips for a basic gun

Hello everyone, I’m making a gun and this’ll be my first gun so basically I don’t know where to start.
I want to make it secure too so please drop your suggestions for it too.

Please explain the basic mechanics like which function of rays shall I use? What’s the best way to sync reload, fire etc. with a ServerScript and LocalScript (For user input) (Remote events are easiest but they’ll be exploited).

Couldn’t really find a helpful video for it on YouTube or any helpful articles on the internet really.
PS: I’m not willing to use any pre-made module scripts for this.

The most basic gun you can make in roblox is a raycast gun which is a big beam going from your gun’s barrel to the position of players mouse, roblox themselves made an article of how to make a basic gun.

To make it work and appear on everyone’s screen you want to use RemoteEvents which make the server receive users signal input and then let the server perform the action you want and in the process making the thing appear for everyone, in this case you would want to create the ray serverside so then other players can see your bullet and so that damage gets registered or else you will see a dead character on your screen but everyone else will see the character as alive.

https://developer.roblox.com/en-us/api-reference/class/RemoteEvent

2 Likes

I know what a remote event is. I asked if there is a better way to do that because remote events are exploitable as you know.

Remote events are only exploitable when you don’t know what your doing when grabbing info from the client

An event for firing gun is very easy to exploit, they can just save the local scripts and see the arguments too if you don’t know. However, can you elaborate on that?

I’d say worry about making the gun first and then worry about exploitability, this is your first time making a gun, and yeah having info on anti exploitability is good too know when, going into it but if you dont even have the gun theres nothing to exploit

My goal is learning how to make a “good” one, I asked for basic in the title because I just need to know which functions I need. I’ll create my script myself.

Alright sounds good
[30 Characters]

Basically everything in ROBLOX is exploitable, there’s no way to make your game 100% exploit proof.

I think you should check out the FastCast gun module. It helps a lot with making guns and there’s a detailed guide on how to use it on this forum.

Personally, I want to try this too. I’m still trying to get used to scripting tools as well and I think this might be a good start. (Though if there is a better way to create a basic gun without using remote events, I would like to know that way as well)

You are not able to fully prevent players from spoofing bullet firing calls, at least not in a way that is good for user experience. If you want to fully prevent players from spoofing gun shooting, handle it completely on the server (ammo, clip size, etc), and just have the player send a target location. This will protect you completely from cheaters, so long as you add a couple checks (i.e. bullet firing delay, etc).

That being said, this will result in a delay from when the user clicks to when the bullet is actually fired which is bad. To overcome this, you have to weigh the good with the bad. When I create guns, I do the following:

  • When users fire a weapon, display it immediately locally, and have it bounce to other players to show up on their screens.
  • When a bullet hits another user, tell the server to do damage to the player.

When the server receives this damage request, verify that they are:

  • holding a weapon
  • how much damage the weapon does
  • that the other person was actually in their line of sight (fire a raycast from the player to the person who was hit and make sure it hits either them or nothing, and that the end location if it hits nothing is within 10-15 studs.)
  • that a bullet was actually fired (store this on the server when the player bounces a call to other clients telling them a bullet was fired)
  • You can add more checks but this is a general idea of how to verify that a gun was fired in a valid way and wasn’t done by an exploiter.
3 Likes