Which is more efficient?

Hi there,

atm I am working on a tycoon kit. For the buttons, I have 2 methods.

  1. I just do .Touched Event for every button on the server and I just do the necessary checks such as if the player has enough money etc etc.
  2. I have a region3 around the player’s character and I check for buttons. I do magnitude checks for the buttons that are in this region. I do this in a loop or under a RenderStepped event. If conditions meet I fire an event to the server and do the necessary checks.

Which is more efficient? I know the second one is definitely less expensive cause you have no Event connections and therefore less memory usage but in terms of efficiency I am not sure.

If you guys have any methods which are more efficient than the above please leave them down below.

1 Like

I’d have to say that the first method is more efficient. The second method is a polling based approach and I don’t think polling ever beats events.

I’m pretty sure .Touched is more efficient since there isn’t a check running every frame. Also, region3 is checking voxels, so it wouldn’t be very accurate. I have heard that .Touched is unreliable.

1 Like

I have used the first method for my previous tycoon and it works fine. However, if it’s on a large scale, you’re gonna have so many event connections that it will use a good amount of memory.

I agree. There are trade-offs you have to make sometimes (memory vs efficiency). You definitely want to sacrifice efficiency if you have a memory problem. The Region3 approach doesn’t seem to be bad at all.

The most important thing to do is measure. I am not familiar with how memory works and how it impacts performance. You could run a test with like 1000 buttons with Touched events vs the Region3 approach to determine which is better.

1 Like

The second method might be less efficient but it’s on the client. Doing that many checks on the client doesn’t seem to be a problem and puts less stress on the server. Putting a loop on the client is better than putting a loop on the server.

Instead of a region3 loop, couldn’t you just do .Touched on the client, fire to the server and then do the sanity checks?

You definitely can but you would be using precious client memory if you do it on a large scale and I try not to use a lot of client memory so everything runs smoothly especially on lower end devices.