The best way to track projectiles

Hello everyone!
I’ve been thinking about this question for a really long time.

What’s the best way to track projectiles

**What’s the best way to track projectiles such as bullets? **

The reason I ask about it is security. I know a good amount of shooters have an issue with security. Exploiters can just fire RemoteEvent or RemoteFunction and kill everyone around even without shooting a gun.

I’ve been looking for a solution for a while now and couldn’t find it. How do developers track their projectiles to minimize any security risks?

Thank you.

I would like to ask if you have made a bullet system before?
I recommend making one first before worrying about security.

There isn’t a “best way” for anything when programming. It depends on your specific case.

For example: you could have an array of physical bullets updated each frame.
you could have OOP setup for different types of bullet e.g. following ones, exploding ones, trail ones, fast and slow ones. I know that some developers put self contained scripts inside the bullet which specifies behaviour which basically means there is no tracking.

Again I highly recommend you make a rudimentary bullet system and show your example here before worrying about exploiters and security.

One common method for tracking projectiles in Roblox is to use a server-side script that creates a “bullet” object when a player fires their weapon. This object can contain information such as the player who fired the weapon, the velocity and direction of the bullet, and the time at which it was fired. The server can then use this information to track the bullet’s movement and detect when it hits another player or object.

To prevent exploiters from firing RemoteEvents or RemoteFunctions to create bullets, it’s important to validate all incoming requests on the server side. For example, you can check that the player who is firing the weapon is actually allowed to do so, and that they are not trying to fire too quickly or at an impossible angle.

In addition to validating input, it’s also important to use a physics engine that is resistant to exploits. Roblox’s built-in physics engine, which is based on the open-source Bullet physics library, is generally considered to be secure and reliable, but it’s still important to test your game thoroughly and monitor for any signs of exploitation.

I have experience of over 6 years of programming on Roblox, of course I do. But didn’t spend too much time working on guns.

Right now, I have my gun system but there are some issues with hit registration, so I wanted to know if I am doing something wrong or if there is a better way to do it.

My way of tracking projectiles is this:
1.Fire gun.
2.Fire remote called “Fire” with start position and velocity. Create and move bullet on the client using this formula: x=x0+v0t+gt^2/2
3.Server checks if start position is’nt far away from character and if there are ammo in the gun.
4.Server saves info about bullet.
5.Meanwhile, the bullet is still moving on the client we check if it hits anything.
6.When it hits something stop moving it, check if we hit a humanoid (if not then it stops) and fire another remote “Hit” with information about part we hit and time the bullet flew.
7.Server checks hit position with 3 raycasts. First one is made from the start pos to the top point of bullet’s trajectory curve (if bullet fly time is less then top point time then script skips second raycast). Second is made from the top to the point when our bullet stopped (using bullet time our client sent). After all of that we check the distance between hit position and hit part and do raycast between them to insure nothing is on the way to hit. Damage player.

Again, I am not sure, maybe I did everything right but in the game I implemented this sometimes have an issue with hit registartion. Maybe that’s just a game problem, it’s kinda laggy lol.

Thanks for explaining. From your original post I was unsure of if you had experience with this sort of thing.

I only have a limited experience with this sort of thing but I would like to ask you to elaborate on how you check on the client side? Is this using .Touched or FastCast or something else?

To find out where the registration stops I would put breakpoints at step 7.

This sounds also suspicious as if the hit position is before the hit part the 2nd raycast check will not work.

Again this implies that there is some distance between the hit position and targetted part.

So, to diagnose I would: Set breakpoints for these 3 raycast server checks and also the client.
Remove the server checks to see if that fixes registration problems. Then go from there.
lower the speed of the bullet so you have enough time to go into the server and follow the bullet. Although from what you have explained you do not have a bullet server sided(Gravity drop slowdown is ^2 btw don’t forget.)

Not recommended but you could also try extending the raycast checks by a few studs

If you have either not many bullets or your bullets are fast e.g. < 1 second flight time I would probably recommend you use FastCast for something like this as it works well for these situations, it’s well documented, supported. Easy to setup. I have used it. But, it’s completely up to you.