How do I make the local bullet part visible to others

I’m currently working on a viewmodel gun system. Due to server latency, I’m spawning bullets locally on the client and using a RemoteEvent to send hit information to the server when a bullet hits a target. The server then handles the damage logic.

However, because the bullets are only created locally, other players can’t see them. I’m not sure how to properly replicate the bullets so they’re visible to other players while keeping the fast-paced movement accurate.

1 Like

Try looking into RemoteEvent :FireClient() and .OnClientEvent().

Although, since the information you are sending is Visual, it might be better to instead use an UnreliableRemoteEvent for spawning the bullet on other’s screens.

The Server can loop through all the players (except the one who fired the bullet) and send them the necessary information to create their own visualization of the bullet. This is done via the :FireClient() method. Then, in a LocalScript, each Client can have an OnClientEvent() signal that receives the information.

If you don’t want to loop through all players, you can instead use :FireAllClients(), but you’d need to add an additional check in the LocalScript if you shot the bullet to make sure you aren’t visualizing the bullet twice.

Then from that point, it’s as simple as reusing the code used to make the original bullet visualization but from another’s Point of View.

Here is some additional documentation that may be helpful.

2 Likes

What I do is the shooter player sends a remote event to the server telling them they want to shoot at this position, the server verifies the remote event, then the server fires to all client, sending the position, and each client simulates the projectile and hitbox. Once a hitbox hit is detected, then only the shooter player should fire the remote event to handle damaging the target. You’d also verify this remote as well, so that it’s only the shooter player that is able to say whether the bullet should damage the target.

1 Like

You could give the client network ownership of the bullet from the server. Be VERY careful with this though as you don’t want to be able to give the client network ownership of anything other than the bullet so do many many checks to make sure.

1 Like

Make the bullets on the server side instead. What I do for gun systems is just doing it all in server scripts and calling a local script when needed for animations and such.

1 Like

Making the Bullets on the Server is Bad Practice, well it depends, if it’s from something that’s rapid fire (Pistols, Machine Guns, etc), then it’s Best to make it in the Client, As Visuals, But if it’s something that needs to be very precise, like for example a Battleship’s Cannon (especially if the projectile is slow and has bullet drop), then do it on the Server

2 Likes

If my gun sends a remote event to the server, wouldn’t the time it takes for the server to process it cause the weapon’s accuracy to decrease?

If you don’t mind, could you please give me an example of how to use a RemoteEvent to visualize a local part?

Yes, I initially considered creating bullets on the server as well.
However, doing so introduced latency between the server and the player, and as Bartholomew mentioned, since my gun has a high rate of fire, this approach doesn’t seem suitable for my weapon.

Using client network ownership also seems like a good solution. I’ll consider giving it a try.

If you make the Projectile in the Server, let the server handle it, if you set the NetworkOwnership to the client, it may end up like Criminality… basically exploiters making guided missiles from the RPGs (since the rockets is made in the server, and the NetworkOwner set to the client)

In Summary, In my Opinion best approach is

  1. Only use Client Bullets for Projectiles from small arms fire, basically infantry weapons or bullets that tends to appear alot
  2. Use Server Sided Bullets for Slower Projectiles that needs maximum precision in all clients, like from a Cannon, or a heavy projectile from something like an artillery
1 Like

Yes, I’ve also heard from people around me about exploits related to Criminality. Due to its potential drawbacks, using NetworkOwnership is something I’ll need to carefully consider. Thanks for the advice.

1 Like

So since you already mentioned how bullets are created locally (and I assume this means the visualization as well), you can reuse that code.

If you haven’t made any visualization at all, then that’s another thing, but if you already have a way for the Owner to see their own bullet, then it’s as simple as copy pasting the code over or putting it into a ModuleScript or Function for multiple kinds of uses.

event.OnClientEvent:connect(function(position,direction)
	
	--[[ Run your visualization code, but instead use the Position/Direction received from the RemoteEvent
	 so it happens from another player's position instead of your own--]]
	
end)

OnClientEvent will be triggered inside a LocalScript when a ServerScript fires a RemoteEvent with either FireClient(player) or FireAllClients().

that’s just the nature of the client-server architecture. In order for all clients to see the bullet, they need the information to render it locally, and you have to do that by sending the mouse pos from the shooter to the server so the server can send it to all clients. There’s no workaround around making the bullet visible to others…unless u did the bullet on the server, which would be laggy

This might be a dumb question, but is it possible to use BindableEvents to send events between players and visualize bullets that way?

No. BindableEvents are not for networking. Gotta use remotes.

I’m sorry, but I’m using the FastCastRedux module, and I’m currently visualizing bullets with the following script:

caster.LengthChanged:Connect(function(cast, lastPoint, dir, length)
    local blength = bulletClone.Size.Z / 2
    local offset = CFrame.new(0, 0, -(length - blength))
    bulletClone.CFrame = CFrame.lookAt(lastPoint, lastPoint + dir):ToWorldSpace(offset)
end)

If the server sends a RemoteEvent to each player individually, do the players also need to recalculate the FastCastRedux trajectory on their own?

How should I visualize bullets when using the FastCastRedux module?

I haven’t had experience with any FastCast Module, so I don’t exactly know how you would visualize a bullet with it.

However, for the recalculation part, you don’t necessarily need to calculate a new trajectory as long as the person who Shot the bullet sends their trajectory information to the Server, and then the Server sends the trajectory information to every other player.

You can create the bullet on the server but still have it look smooth for the player who shot it by setting its network owner to the client.

Edit: Nevermind what i said, since the bullet isnt an actual physics object you should fire a remote event to all clients with information on the bullets trajectory for them to recreate themselves.

Since you’re using fastcast, run whichever function that created the bullet, in the client instead of the server… it won’t really matter… except it obviously won’t damage, so you have to use remote events for the damage, and create the bullet in all other clients WITH the same Origin and Direction, so it Replicates to everyone