Mining System & Client/Server Relationship Help

Hi all! I am new to the dev forum and game development in general! I am building a voxel mining simulator as my first game, but I’m having trouble finding resources to help me understand the best structure to manage multiplayer mining. Below is a description of how I have set things up so far and the 2 questions I have. I can post my scripts as well if this is not clear enough. Any feedback or comments on this would be very much appreciated.

Mining System Structure:
Client script parented to the mining tool uses UserInputService and ray casting to identify the part a user is hovering their mouse over. If the target part is in range and the user holds mouse button 1, a remote event is fired to the server. The remote event passes the tool’s stats, stored as NumberValues, and the tool’s target block.

A single server side script that I put in ServerScriptService listens to the remote event and runs a while loop that damages the target block after a wait is complete. The damage and wait time is based on 1. the tool stats received and 2. NumberValues parented to all minable blocks that represent total health and base mining speed.

My Questions Are:

  1. Is this client/server structure the best way to manage damage dealing systems to non-humanoids in a game? Sometimes when there are 2 players trying to mine blocks at the same time, the mining functions don’t run. I am trying to figure out if this is because of the structure of my client/server scripts or if I just need to improve the code itself. Can a single server side script be run multiple times instantaneously by different players?

  2. Is storing the health value of a block as a NumberValue parented to every single minable block a bad idea? I structured it this way because I want any client to be able to read a block’s health value and show a gui with that value. But would a table be better? When I try copy a few hundred of these mining blocks, my computer starts to chug very hard (even with an i7 and 2070 gpu).

Thanks again!

1 Like

Is there any reason why you don’t just validate this information on the server without passing the tool status as a parameter? This could be spoofed by an exploiter and overall is kind of redundant if you can directly reference the tool through the server.

This depends on what’s actually going on in the server script. If a RemoteEvent or RemoteFunction are being fired and the code in question is connected to a OnServeEvent or OnServerInvoke event, then yes, single server side scripts can be run multiple times by different players. As far as I can tell your network seems to be relatively well established. A possible solution for your situation presented in question #1 would be to pass the part in question as a parameter of FireServer() [which I think you’re already doing to determine what part is being mined.] Store that part in a table, and from there check to see if that part is already being mined. If it is, you can apply specific logic to “share” that part with multiple users.

I want to say this comes down to preference, but generally speaking, no, this is not a bad idea. Just make sure you validate the health value on the server before actually inflicting any “damage” to said part.

2 Likes

Thanks a bunch for the reply, super helpful!!

This could be spoofed by an exploiter and overall is kind of redundant

I see. I’ll definitely change this!

make sure you validate the health value on the server

This sounds like a good point, but I don’t fully understand the purpose or how to do it. Would this just mean implementing some kind of if statement that only continues the loop if the health value is what the server script thinks it should be? What does this protect from?

1 Like