Voxel Destruction Optimization (Using .Touched)

I’m creating a voxel destruction system, it will be very small scale with probably less than ~500 parts on screen at once. The system I made looks really cool. However, it is extremely slow and clunky.

Here’s what happens:

The system works by every voxel having a script that checks for a .touched event, then checks if its the player. If it is, it launches then destroys itself.

I know this is an extremely slow way to do this, so I’m wondering what a better approach would be? So far I’ve thought of a couple things

  • The player uses a local script to check if they hit a voxel, if they did send a remote event to the server to verify and destroy the part. (I feel like using a lot of events would slow it down

  • Using a model with the voxels and a hitbox to detect the player, then cycling through the voxels in that model to see which are touching the player.

Any ideas?

You should probably have that effect happen locally and not on the server. You can then have something like this:

--- Server:
on notify:
	if correct: -- verify
		notify all players
	else:
		notify sender that it is incorrect


-- Client:
if hit:
	notify server
	Destroy part


on notify:
	if not correct:
		undestroy part
	else:
		destroy part

This will both decrease the delay (as the client must wait for 2x their ping to the server for results) and server load (as all destruction is handled on the clients).

1 Like