What's the best way to handle attacking troops in a tower defense?

Hi, I want to make a troop system but how would I handle the client-server side of things? Each troop will have a cooldown, should I handle this cooldown on the server or the client? I already know I will need to render the special effects and animations on the client side but should I use a FireAllClients Remote Event to the clients to render the move and attack on the server or I use FireServer to attack on the server, do checks and then render the move on the client?

If there are any questions, you can ask me! Btw, I use OOP style programming

1 Like

Best way of client - server communication is always the client sending a request, the server checking if it’s correct and then performing the specified action. Spawning and the cooldown of it should be performed by the server.

To add onto this, to achieve this you’ll need to make use of RemoteEvents as they allow for server scripts and local scripts to communicate and exchange information between one another.

So, to clear things up, cooldown of the attacks should be done in a heartbeat function on the server and then the actual damage dealing will be a function on the server right after the cooldown has been reached, then send a remote event to all the clients to render the attack?

Fire All Clients will send the attack to all players on the server is that what you want?

What if you need a touched event or a delay between the rendering of the attack and the actual damage? For example, a sphere that shoots slowly and everything it touches deals damage, how would I handle that? I can’t exactly make a sphere on the server or delay the attack on the server either.

1 Like

Uhh, I guess so yes, I want to make a system where everyone sees the attack and it runs smoothly and accurately

I still don’t have an answer yet, can someone reply please?

Be patient someone will answer if they know the answer to it.

Ok, I was just afraid no one will see it, sorry about that

Well you can create a “Hitbox” part that you send out on the server to check which things have been touched and then do the sphere visuals on the client-side. For delaying the attack, you can create an edge case for attacks that need to be delayed on the server that isn’t a problem.