Help with Synchronizing the Client and Server

Then I guess doing it on the server is fine, thx. I will try it and see if it is a big deal.

2 Likes

Honestly the only thing I’m worried about is if it just kills the client randomly when they don’t even touch the object.

1 Like

Remember my advice though, if you do eventually start to experience some lag then I recommend adding a debounce for the server to temporarily reduce the amount of tweens the server is handling at the same time to give it time to process and breathe so-to speak

1 Like

If the Touched event is on the server then technically the client would die at the correct moment even if the sphere is still far away from his point of view

Remember that what the server sees is the most trustworthy in the end

1 Like

debounces? what if a longer wait?

1 Like

Debounce does not equal wait although in your case if the server is the one creating the spheres on its own instead of after a signal from a client then a longer wait in your loop would work too to solve lag issues

2 Likes

And sometimes idk why, but touch events sometimes have a big hitbox, or is it just the size of the part?

1 Like

Touched events have always been a bit wonky in the way they work. If you really and I mean really want a more accurate result you’ll need to do something like this instead of using Touched

But I don’t recommend it unless absolutely necessary because doing it for a lot of different spheres would cause quite a bit of lag

1 Like

Oh yeah I was also thinking about disconnecting the touch events, like after the sphere got destroyed, it will create a memory leak. So how am I gonna do this?

1 Like

Oh and to make it keep detecting if a player touched the part, I keep enabling and disabling the part’s CanTouch property.

1 Like

If you destroy the sphereClone on the server using :Destory() or game.Debris:AddItem(sphereClone, 0) then any connections the sphereClone has will be automatically disconnected

If you want the sphereClone to keep detecting all players inside before it’s destroyed then you will have to use the method I linked, but most likely you will need to either reduce the amount of spheres being created, find a way to spread out the creation of the spheres, or destroy them quickly if you want to avoid lag

2 Likes

Wait so all connections in a damage script that is a children of the sphere will get disconnected? are the local variables garbage collected too?

If the sphere is properly destroyed using one of the methods I mentioned then yes, any scripts with connections or locals that are a child of the sphere will be automatically garbage collected as well

1 Like