Hello everyone,
I’m seeking advice on efficiently passing information from a client to a server for a gun system I’m developing. Currently, I’m using RemoteEvents, but I have concerns about the practicality of passing numerous arguments when firing.
For instance, when firing a weapon, the client-side module has access to properties like sounds and damage. The server needs this information to execute the code. Should the client pass these variables when calling the event, or should the server define them?
My concern is that I am passing way too many arguments to the server script (located in ServerScriptService) in a single fire. To me, it seems impractical and tedious and I seek any method that would make this easier.
Previously, I had both client and server defining everything, but I’ve now separated them. Any suggestions on a method that allows the server to access all necessary information from the client script without passing too many arguments?
Your help is appreciated! If you would like me to provide an example, I will try my best.
Thank you!
I would put most of your information on the client for performance. However, you might need to keep some things on the server. This is because when you are firing from the client to the server, passing in an argument that is only on the client will be nil on the server. So, if you create an instance on the client and pass it through the server, it will be nil because the server hasn’t replicated it. If you want to pass it through, you will need to pass a string, boolean, number, etc, and not the instance.
If you still have too many arguments passing through, I would put them all in a table and pass the table so it’s easier to look at.
1 Like
Thank you for the response!
I do handle most of the things in the client but for visual effects and damage, it must be handled by the server for everyone to experience it. I just need the server to access the gun and its properties without having to make variables for everything all over again.
I believe I should have clarified that I am not passing instances, but variables and properties. Stuff like sound IDs, the player’s gun model, etc. This can all easily be passed to the server, but I have so many things to pass, and storing it all into a table seems very impractical. I much rather pass it instead of having the server script define everything all over again. I would much rather have the server be able to access everything with ease, but if a table is my only option then so be it.
When I mean pass it into a table, this is what I mean.
local Args = {
Number = 4,
Damage = 50,
Cooldown = false,
Tooltip = "Cool Gun?"
}
-- To access it in the local script
print(Args.Number)
-- To pass it into the server
RemoteEvent:FireServer(Args)
-- To recieve
RemoteEvent.OnServerEvent:Connect(function(Player, Args)
print(Args)
end)
Let me know if I missed something, thanks!
1 Like
Thanks. Yeah, that is what I was doing in the meantime, but my table is really large so I had hoped I could skip the table and have the server already have access to everything somehow.
I’ll continue using the table for now!
1 Like