Server Side bullet shooting

I have a bullet object and right now i just have it create when you click in a local script.
But i dont want it to be only local side i want other players to be able to see it.

This is my bullet script as it is in the local script

		local bullet = game.ReplicatedStorage.Bullet:Clone()
		bullet.BodyVelocity.Velocity = player.Character.Head.CFrame.LookVector * 50
		bullet.BodyPosition.Position = player.Character.Head.Position
		bullet.Position = player.Character.Head.Position
		bullet.Parent = game.Workspace
		script.bloop.PlaybackSpeed = math.random(5,15) / 10

And before you say use a remote event… I tried that.
When i use a remote event, it does this.

Please help

Use FireAllClients() and create the projectiles locally for each client.

1 Like

I’m going to say it… Use remote events. If you create the bullet on the server then it shouldn’t lag (If it still does then you might want to not rely on the physics engine to much). If you let the client spawn the bullets, then it is very easily exploitable.

Are you saying to simulate the physics on every client? if so, every player could have a different vision of where the projectile is. it will be very messy

not really I tested this and it works perfectly fine visually

1 Like

Did you test it in multiplayer? For example, if a player peeks around a wall and shoots, and walks back behind the wall very quickly, by the time the other players are given the signal to simulate that bullet, it will spawn in the wrong position.
Nvm, misunderstood what you meant.

yes just messing around with a friend but I actually didn’t go much into detail but looked fine in both sides

No, the physics details are provided by the server, but the projectile creation and handling of those physics is done by the client.

Many gun kits follow this kind of system.

Client shoots projectile from gun which in turn fires the server → server performs all of the necessary calculations and fires every client → each client creates the projectile and uses the information provided by the server to animate the projectile.


I might try this, But my only question is how would i detect when the bullet hits something with this method?

Here’s my thought process on how to go about doing this.

  • You need a reliable and accurate bullet simulation.
  • You don’t want it to be exploitable, so you can’t completely trust the client.
  • Can’t simply fire to server and simulate from there as it looks laggy, has input delay, etc.

What I suggest doing is this:

  1. When firing a bullet, simulate its trajectory on every client separately. To do this, you will need to fire the bullet on the client as well as fire to the server, then tell every client to simulate a bullet for that player who fired it simultaneously.
  2. When the bullet detects a hit on the client that fired it, validate that hit on the server through some sanity checks (i.e. check if it went through a wall, was too far away, was fired on a player that they shouldn’t have vision on, etc.) If it doesn’t pass the sanity check, then flag that player for a sus shot, and if they have lots of flags then kick them. (I don’t suggest banning as false positives always exist)

Of course, you’ll need to do some extra stuff to ensure the bullet hits don’t look wonky for other players (i.e. ghost hitboxes).

I suggest using FastCast for projectiles, by the way. They help a lot with modeling projectile bullets and handling hit detection.

1 Like

I should add that the bullets will not be hurting other players.