How can I create a tracer effect via beam for my raycast gun?

Hello Developers!

The title simply says it all, how can I do that?

1 Like

You could do make a part, where the gun hole is and there where you shot. And then after you just attach the beams, did you mean this?

1 Like

So basically:

  1. Get the mouse position.
  2. Add a part where the mouse is positioned at.
  3. Attach the beam to the gun to the part?

Sounds easy, but idk if this would cause lag due to constantly adding the part to the mouse position, I think?

1 Like

Not necessarily, adding a part everytime you click isn’t the costly part but its about what you do with the part. I suggest you create the part on the client, send a remote to the server and then replicate the parts on all the other clients.

Hmm, mind if you show me an example script if that would be okay of you?

1 Like

Sure! here is what it would look like on your client side:

gun.Activated:Connect(function()
   -- do gun visuals
   gunRemote:FireServer()
end)

Server side:

gunRemote.OnServerEvent:Connect(function()

     -- verify shot


     replicateBulletRemote:FireAllClients()  -- the only issue here is that since we are using fire all clients, it will fire the client of the player who shot it. you can loop through all the players and fire their client except from the player who shot the gun.

      -- damage the player who was hit, etc
end)

Another bit of the client:

replicateBulletRemote.OnClientEvent:Connect(function(playerWhoShot)
   -- replicate bullet, do gun visuals
end)

This may seem like a lot but I believe its the best way of handling weapons without causing unnecessary lag, its a bit complicated so if you really want to you could handle bullets the usual way

Ah alright then! Thank you very much.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.