Script Activity Rate not Dropping

Hello, I have been recently having this lag issue with my game. It’s really critical at the point where after a while, players with low-end computers will experience spikes very often.

In the last test I ran for around 25 minutes, I’ve got these results from 2 scripts that cause the issue.

for those who can’t view the image, they reached a rate of 8 gb/s and 6 gb/s

EffectsController:

local event = game.ReplicatedStorage.Events.BulletHoleEvent
local event4 = game.ReplicatedStorage.Events.MagEvent

event.OnServerEvent:Connect(function(player, ...)	
	local tuple = {...}
	
	local ignores,origin,direction,size,splatter,particle,model,attachment,attachment2,fromcast = tuple[1],tuple[2],tuple[3],tuple[4],tuple[5],tuple[6],tuple[7],tuple[8],tuple[9],tuple[10]
	
	event:FireAllClients(player,ignores,origin,direction,size,splatter,particle,model,attachment,attachment2,fromcast)
end)

event4.OnServerEvent:Connect(function(player, ...)
	local tuple = {...}
	
	local model = tuple[1]
	
	event4:FireAllClients(player,model)
end)

MotorController:

local motorEvent = game.ReplicatedStorage.Events.MotorEvent

motorEvent.OnServerEvent:Connect(function(player,...)
	local tuple = {...}
	local motor6dList = tuple[1]
	
	motorEvent:FireAllClients(player,motor6dList)
end)

These bits of code are the whole scripts, nothing is cropped out of them.

Please help, it’s driving me crazy at this point!

1 Like

Are the remote events being fired constantly or very often? To check, how about you add the good ol’ print() in each function?

1 Like

For MotorController, yes, to be exact its being fired every 0.1 seconds. For EffectController however, it’s fired whenever a player shoots.

That’s your problem. Remote events are not supposed to fired that quickly. In fact, the wiki article for remote events says each remote should send under 50 KB/sec!
If you are firing that remote event 0.1 times every second with a turple, it’s most likely going to impact performance (depending on how large the turple is).

On top of that, the effects remote event is (from what I can see) being fired whenever the gun shoots. Players could be spamming the gun or using a gun that has a fast firing rate (again, depends on your game).

Thanks for responding, I just realized the limit while reading your reply. Do you have any idea how to accomplish this without… RemoteEvents then? Any workarounds perhaps?

It honestly depends on what game you are making and how you want to achieve this. I obviously don’t have the exact details of what your game is, so I couldn’t exactly tell you how you should do this.

I recommend looking into Network ownership or just doing things in the client.

Basically, my game’s an FPS shooter type of game. I’m trying to optimize the server the most by only sending events instead of creating parts, muzzle flashes and sounds so no effects are created on the server and every players ping stays at their average.

Example:
-Player1 shoots, a bullet hole appears on his screen instantly
-fires to the server, server fires other clients the CFrame of the bullet hole, same thing happens for them. The server is almost left untouched.

I can explain more of it if you still need me to.

The data maximum per second and the sending rates are two unrelated concepts. OP’s code looks as though its only replicating data through the server for the sake of client-side handling for various actions, so the data they’re sending is probably only a few bytes. 50 KB is an astonishingly big limit.

That being said, the remote traffic is an issue. Remotes should not be fired as often as every 0.1 seconds. If a case like that occurs, then it’s indicative of bad structure that needs to be fixed. This you’ve addressed in your post already.

1 Like

So, do you think I am able to replicate this with another method, maybe by using RemoteFunctions? Would I achieve anything different?

RemoteFunctions would only make this worse, especially if it’s the server invoking the client and you don’t have a wrapper function when doing so. I doubt you need the receiving environment to send back any data in the first place.

Thanks for the info, then I suppose the only way to replicate this just right is to sacrifice a bit from the server?