Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Performance difference between Server and Client for Projectiles?

Over the past year or so, I have been developing a 'wand' projectile system.

The system I made would work by: Player Equips Wand, Player Clicks Mouse, Local script connect to a remote event sending the position of the mouse.hit as well as the tool, The server then receives the message, Server creates the spell, Server then fires the spell via raycasting.

However, I was recently pointed out that by firing it over the server and allowing the server to execute all of it, including the movement; It could create latency on the server as it's high demand, especially if there are a lot of player.

They then suggested to me about using 'FireAllClients'.

My first question, how does manipulating the projectile through the clients rather than the server create less latency?

Second question, how would the server know when the projectile has hit an object if all players are firing this projectile?

Third question, due to the projectile being fired under client conditions and not server, if an exploiter came along, could they move their client sided projectile to hit a different position and have a different hit outcome? Eg. Instead of spell hitting the wall, it hits a player instead?

If anyone could explain the benefits of FireAllClients rather than doing this all server sided, I would be really appreciative of it...

If possible, could you give a method on how the FireAllClients could be used within a projectile circumstance.

Eg. Dev Forum thread:

ClientA fires a Event telling the Server to make a Projectile Part on all of the clients, FireAllClients, Clients have a OnClientEvent that creates a Projectile Part with the Position Argument passed from the server (The RootPart’s Position of the Player who fired the event in Step 1), Clients use Region3 to detect if the Projectile has hit something, if it did Destroy the Part, If the Client is the same as ClientA that fired the Event in Step 1 and the Projectile Hit something, Fire a event with the Position Argument that the Region3 detected a Humanoid at and make a Region3 on the server to validate that there is something hitting the Region3 at that Position.

If you have any other better methods, please let me know!

Thank you!

2 answers

✓ Accepted answer

I would have the client checking for input, so when the mouse button is pressed, it sends information to the server to start a line of tiny raycasts from the wand in the direction of the target, updating every heartbeat. As for hit detection, I would check the distance of the ray to the player or players directly in front of the player (if there are any), and if the ray eventually finds a player in the path of the ray, then a hit will be detected.

Now as for the client, when it sends the input to the server, the server will then fire all clients, giving them the same function that would be running on the server, except only the server will only handle hit detection, and the clients will only handle the visuals, but both will be running the same raycasting function.

To summarize: Client detects input, and fires to server, then server fires all clients and starts raycasting at about the same time that the other clients start the spell.

And to answer your questions directly:

  1. How does manipulating the projectile through the clients rather than the server create less latency?

The server likely only has a CPU unlike your computer, which most likely will have a CPU and GPU, that's the biggest reason for handling visual effects on the client side and handling only hit detection and raycasts on the server. You wouldn't want to force the server to handle graphics processing at the same time as trying to keep the whole server synced, the less work you give to the server, the easier time it will have keeping everyone on the same page.

  1. How would the server know when the projectile has hit an object if all players are firing this projectile?

  2. Due to the projectile being fired under client conditions and not server, if an exploiter came along, could they move their client sided projectile to hit a different position and have a different hit outcome? Eg. Instead of spell hitting the wall, it hits a player instead?

Due to the clients only handling the visuals and the server handling the hit detection, this will not be a problem. If a client hacks the projectile to hit someone's head like aimbot, then it might show them that they hit the player, but nothing will actually happen to the player. You might also want to check if a player is within a valid spot (within the map bounds) when they fire because some more advanced aimbot scripts actually spoof the player's position so that it looks like they fired from above the map down at the head of an enemy. This would seem like a valid hit, if you only checked the end position of the hit, and not where the raycasting started.

You should use server for hit detection (raycasts) and use the client to visualize the spell and have all the spell effects handled on the client.

You should let the server handle as little things as possible. When you have the option you should (almost) always let the client handle it You want to load as little as possible on the server because its already busy syncing all of the clients together and handling all the instances etc

This discussion is preserved as it was. New answers, comments, and votes are closed.