[SOLVED] FireAllClients crashing my frames to the point of app crash

So essentially the only thing my server script does is fireallclients so all clients can see bullets being replicated to the server. The client script is beautifully coded and shows absolutely 0 lag. The server script shows it is generating massive lag but the only thing it is doing is fireallclients. Please help. I will paste the code for it below so you can see.

game.ReplicatedStorage.Visualizers.Server.OnServerEvent:Connect(function(player, startCFrame, GunBarrelCFrame)
if DB[player.Name] == nil then
DB[player.Name] = true
wait(0.01)
game.ReplicatedStorage.Visualizers.AllClients:FireAllClients(player, startCFrame, GunBarrelCFrame)
DB[player.Name] = nil
end
end)

Can you please post the code where the client is receiving and handling the event.

I managed to solve this on my own. There are 3 key things to this that everyone needs to know

  1. You MUST put some form of wait() in your local script when using client events. This was by far the most important change I made to my local script and helped to completely eliminate the lag.

  2. You should ALWAYS put your local script in starterplayerscripts instead of startercharacterscripts when you are experiencing any lag. It will prevent the script from refreshing itself every time you die. This was a big help in eliminating the lag on character death.

  3. You should learn how to reuse the same parts rather than generating and deleting the same parts over and over again. This was a great help to my overall performance as well. However, it is not entirely necessary especially if you are not spamming the events at a fast speed.

Corrections:

  1. You only need some sort of yield (i.e. task.wait()) if you are doing quick refresh looping or infinite looping. RemoteEvents do NOT need task.wait().

  2. While starter player scripts IS good, you need certain scripts in the StarterCharacterScripts to completely destroy them and prevent memory leaks, which I suspect will happen with your script.

1 Like

While both your answers might be correct, my problem specifically was happening with the spamming of remote events and anyone trying to use a non raycasting bullet system might encounter this same issue until they follow my instructions.

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