Referencing a object that exists on the client... in the server

So this might appear basically impossible at first, but its doable, but the way I’ve done it is horrible and I figure there must be a better way.

So I want to have client shoot a gun, that gun shoots instantly with no input lag on their screen, the server receives the an event saying the gun was fired, adjusts the bullets position to where it would be given the latency, and then does its bullet physics ( will later move this onto other clients but for now this is how it is).

The issue is, the hit detection being on the client, the client needs to tell the server “Hey the bullet hit something” … but since the bullet only exists on the client… this can be quite difficult.

The way I fixed this was by naming the bullet something special when it got created, something that would never repeat itself, tell the server the name and when the bullet hits, send this unique name to the server so it can indicate what bullet hit. This feels like a horrible solution, not only will it be tricky to prevent against exploiters (will have to verify all the bullets exists and the name is valid etc) its extremely messy and feels like a way to do things in 2012.

Is there a way I can somehow reference objects that dont exist more easily? Like maybe with tags? Or did I set up this entire system wrong? Kinda stuck on what to do.

As an alternative, network ownership might be good. Network Ownership | Documentation - Roblox Creator Hub

I reccomend looking at how FastCast does it and implementing/learning the methods used.

I actually use fast cast to make this work, but they have no client/server synchronization

networkownership doesn’t work for anchored parts

Ah okay, I wasn’t sure as you didn’t state that.

However, why aren’t you using raycasts instead? Raycast from the gun on the client to check if it hit a player (and to avoid latency for the shooter), and confirm the hit on the server and deal damage. Of course, there may be a reason why you chose to not opt for this method, but it’s worth a try.

I am using raycasts, but I still use a physical bullet for aesthetics. I also do a client and server raycast, but thats the issue, I can’t find a way for the client to tell the server that the bullet hit, without using complicated part names.

From what I understand, you’re looking for a way to notify all clients to remove a physical bullet model after it’s hit a player or object (which is decided by the server)

Your solution seems pretty similar to what I’d do (if it’s important that the bullet position is determined by the server) - if every bullet has a unique ID that’s the same across clients, you can broadcast to all clients to remove the bullet with that ID.

However, I’d probably switch to fully simulating the bullet models on the client. Since they’re only a visual aid, they probably don’t have to be extremely accurate, so this solution would simplify a lot of parts. This way, you can simply destroy the bullet when it hits something on the client.