It is impossible to synchronize the client and server because both can be delayed cause of multiple things.
For exemple, the client can have delay because of its FPS, and the server can have delay because ressources taken, network ect… so even if you can minimize this delay for people that have a good PC and a good network, it will not be the same for everyone.
The only thing you can do in your case is to use a remote event, and Fire it from server to all client at each start and end of attacks.
@T3_MasterGamer explained to me in a message that if you want to detect if the sphere hit something using Touched event on the server (which I also recommend for security purposes) and the sphere is being created on the server, you will need to move it on the server as well else the sphere will only move on the client causing the event to work incorrectly
Although if the client is experiencing network (internet) issues there will be a mismatch between the server tween and the client tween that I confirmed with a test just now (the server tween will complete before the client tween does even with the exact same tweenInfo configuration)
There isn’t a way that I know that can solve this problem unfortunately
Think about the problem: Us programmers and game designers rely on the server to secure and/or relay (replicate) data being sent to players in the game. When you play the game using the Roblox Player or website (since Studio uses your PC as a server for testing) Roblox selects a random server that’s available to host your game (from what I know it will try to find a server close to your locality when possible to minimize any delays). The server no matter where it’s located also relies on the client’s internet connection to do its job, so if the client has a bad internet connection they might either miss data being sent altogether or retrieve the data too late. The only way to solve this problem is by forcing players to have a good internet connection but obviously this isn’t possible and also has a risk to loose out on a lot of possible players since unfortunately good internet connections aren’t cheap (I speak from personal experience, my internet connection enjoys randomly disconnecting when it feels like it)
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
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
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
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
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?
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
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