Passing Parameters via RemoteEvent Frequently: Is This Resource-Efficient?

Hey!

I am trying to rewrite a system within my game to be more optimal and resource-efficient, but I am having some trouble as to how I should go about rewriting it.

Yes, I did some research beforehand on the Forum, however, my research did not satisfy my question.

My system includes the use of RemoteEvents, one of them being used more often than the others. I need to pass on a lot of parameters with said RemoteEvent, though I am afraid it will cost me of resources. So, my question is: is it not good practice to pass lots of parameters through?

Below is a small snippet of the code. Said code is being executed on the server:

--// Server-Side Code
function Raycast(player, part, startPos, endPos, damage, ammoUsed)
    --//Code execution here...
end)

As shown, a total of six parameters are being passed on. Will this cost the game of resources? All parameters are needed in the function. Plus, the RemoteEvent is being fired very frequently.

How should I go about rewriting this code? I would appreciate the help! Thank you.

-theplushedguy3

1 Like

I don’t think that the parameters are going to lag your game, but be cautious of the fire rate. I don’t know how quick you’re going to fire the events, but it shouldn’t be too many times (I’d say <10 times/second).

1 Like

What else could you do in this situation? Different values? Is that recourse efficient? I think it’s made obviously clear that they want you to use the tuple arguments in the FireClient/FireServer function. Whatever alternative there is, it may be less efficient than the already existing method of going through the remote event.

OOF. There might be a slight problem with your statement.

Unfortunately, the RemoteEvent will sometimes fire more than 10 times per second. This system is tied back to using Tools. Some specific Tools fire the RemoteEvent more than the rate you described.

Parameters have nothing to do with resources or efficiency, you can make as many as you reasonably need. Just don’t make so many parameters that you can forge from in the function itself because a large amount of unnecessary parameters may indicate code smells and bad structuring.

What really matters in this scenario is what exactly you’re passing. All these parameters are sent over the network as a whole message which contributes to the allowed data consumption per second. I can’t remember if the exact number is 50 or 60 KB/s, it’s on the DevForum somewhere.

If a remote needs to fire several times per second, you should heavily look at reevaluating your structure even then. Remotes shouldn’t be firing so often. What is your specific use case?

3 Likes

You shouldn’t send over the damage, or anything exploiters can abuse. Exploiters can modify anything sent over, so you shouldn’t do this

1 Like

Like I have stated when replying to another person, my specific use case ties back to a selection of Tools that are compatible with this system, even more specifically, guns. A few of these guns, e.g. a submachine gun, fires the RemoteEvent more than 10 times per second, which might be the backstabber of this problem.

I do see your point in this statement. There is at least one parameter that does not need to be passed on. And no, I do try to structure my scripts in the most readable and efficient way as possible. If I need to send in more snippets of the code, I can.

Thank you for your input on this matter! I appreciate it.

Noted. I will try to pull this data elsewhere in the script. Thank you for your input!

I recommend you always render these gun tracers locally. Have clients render them individually to reduce the load on the server.