Server side hit detection

I already tried that, but because I’m replicating the bullet on the client side, any server script parented to the bullet doesnt work for some reason, even when I fire a remote to the server.

That would cause unplayable lag.

I’m replicating the bullet on the client and then telling the server to copy that to all other clients to avoid lag, but now I have a problem with server side hit detection

I wouldn’t put a script on each bullet, that could cause a lot of lag if you have a lot of bullets at once. Instead, have one script that manages all bullets, either using an array or Collection Service. The centralized script would make it easier to code around, as everything relevant to bullets goes to one script instead of finding the corresponding bullet.

1 Like

Again, FastCast would probably solve this issue, but to solve it with your physics simulation approach, you’d want a duplicate bullet on the server which has the script attached to it. The server can’t parent a script to your client-sided bullet because the bullet does not exist on the server.

Could you link some topics/DevHub post or explain how I could do that?


Arrays/Lists/Tables/Dictionaries: Tables

Collection Service: CollectionService

CollectionService functions the exact same as putting scripts in each of the objects afaik. Using an array could definitely be more performant, but I’d worry more about the physics. Roblox (and most game engines for that matter) can’t handle many physics parts being active at once, especially not for many bullets colliding everywhere.

The script is already in the part that gets cloned.

Yes, but cloning it on the client won’t replicate the script as all server scripts aren’t visible to the client.

Sure, personally I would just use raycasts, there are times when projectiles are the way to go, like cannon balls or rockets. I’m giving Unbound the benefit of the doubt and trying to work with projectiles.

I see, but I have no idea how to use FastCast.

Again, I think FastCast is the best solution here, as it gives full projectile behavior while maintaining the vastly superior performance of raycast-based systems.

It’s actually pretty simple, the creator provided a sample / debug gun along with the module which has everything you’d need in it, all already implemented for you. Basically no knowledge needed. I’ve made my own guns in minutes using the scripts inside of it, and you can tweak that script however you want to achieve your desired gun.

@Monkepath gave you a clear answer. I’ve just finished working with an FPS framework too, I used FastCast on both client-side (just for the projectile visualization) and server-side (actual hit detection). FastCast actually handles lag (FPS lag not ping) quite well using the delta time, so even if the server and client have different FPS it still works fine.

I would prefer to use projectiles as I will be using cannons/Turrets in my game.

right, you can do that with FastCast

And FastCast does exactly that! It uses projectiles, only difference being that instead of using the costly roblox physics simulator, it uses raycasting at every physics timestep to give the exact projectile arc without all of the unnecessary calculations done by the physics engine.

Can you elaborate on this?? I’ve resorted to doing client side hit detection, as server side is just way too unreliable and players have mentioned countless times that on their client they hit somebody, but that person doesn’t die.

I know most FPS games on Roblox use client side hit detection too

I did that at first too, but there are many, many bugs with that.

I have come to a solution: I made the projectile Replicate to all clients (through remote events) thus, not causing any lag, and then I also at the exact same time, fire a server-side projectile (which is invisible, so no one sees the lag) to handle the hit detection and damage.

That’s already what I’m doing :grimacing: however, even so, there’s notable difference with hit detection done on the server. Players can visually see their bullets hitting a target, but the target doesn’t die cause the server says that player is in a different spot

I don’t think there is, my friends and I have tried and tested my gun system multiple times, and no one saw any difference.

That problem would be due to the players own lag… like in most gun games, cant be helped.

The lag I’m referring to is when the projectile gets parented to workspace, there’s a fraction of a second pause in the projectile, there is no difference in the client projectile position and server-sided projectile position, (yes, of course there is a difference, but its so small that it will never make a difference in gameplay), also, I’m handling the damage on the server, so I don’t have the problem of getting false positives.