Performance wise, which method of handling hitboxes is better?

I have a hitbox which is just a part welded to the character. For this hitbox, I have a setup (see image below) where each hitbox has a server script and a local script.

The local script primarily handles touch events, and then sends the touch information to the server to verify/act on. Is it better, performance wise, for example, in a server full of 16 players:

A) Have 16 hitboxes where 16 local scripts are firing touch information to their respective server scripts (so essentially 16 server scripts)

OR

B) Have 16 hitboxes where 16 local scripts are firing touch information to just 1 server script

My main goal is to reduce spiking and improve script performance. Is any option better than the other, or does it even matter?

Screen Shot 2022-01-31 at 7.44.49 AM

C) Neither.

One LocalScript, one Script. Both respectively handle existing and newly added hitboxes to the character and send information across the network when necessary. The LocalScript should be in the character or PlayerScripts and the Script in ServerScriptService.

On the whole this is more of an organisational pattern because you’ll still end up with the same number of connections as there are hitboxes so the underlying technicals won’t necessarily differ.

In other words: B is better than A but both solutions have holes in them. If you were asking me, I’d tell you to just use 1 script for both environments instead.

5 Likes

both of them are very inefficient.

also, I wouldn’t recommend using .Touched event for hitboxes ( Touch Events: The main reason why you should, under ANY circumstance NOT use this is because it isn’t that good at detecting things. For example. Touch events have TONS of issues, server delay, and much more. So using this for a hit box isn’t the best idea) I would recommend using Hitbox Service, easily create Accurate Hitboxes using minimal scripting!

1 Like

Why can’t you handle the “.Touched” events from server scripts in order to circumvent the need to transmit data from the clients (through local scripts) to the server?

1 Like

For my game’s purpose, often times you’ll have 10+ hitboxes colliding constantly with each other which would create severe lag on the server.

Also, I’m much happier with the client handling the touch because it’s a lot more accurate and it feels near-instantaneous as opposed to delays handling it with the server.

As far as I’m aware, a lot of games use client-side approaches for determining touch/collision.

Client-side determination for touch/collision is asking to be exploited, just a heads-up.

Anything on the client can be modified by the client.

cast a region3 and loop through/filter the returned elements down to the ones u want