Optimization in a Tower Defense?

Hey, and thanks for reading in advance.

I’m nearing the alpha phase of a TD game I’ve been working on that’s stylized after the Kingdom Rush series. In hindsight, though, it might’ve been a good idea to consider a system utilizing fewer script instantiations.

As of now, each enemy and tower has a unique serverscript that runs AI and relevant mechanics through a while-loop that repeats on the shortest wait interval possible. In previous practice, doing this in excess tends to cause any game to grind to an inevitable halt (and of course, memory leaks are a constant source of concern).

My question to those that may have attempted similar projects - am I doing this incorrectly? Should I be attempting to centralize AI or re-structure most of the game logic so that the client is doing the brunt of the work?

Help or advice is appreciated.
(Edit: Wording for clarity)

1 Like

I guess you can do some changes

Those both will make it just fine since currently, from what i read, the game will have issues with keeping up on what is happening.

1 Like

Using module script to control multi AI and having it run on client for movement etc can help ease up server use also makes it look smoother on the client sometimes this depends on the use case

2 Likes

A similar way of getting the client to do the work is by having the server only store and update enemy position and stats, but not the character itself.

To get the client to show the enemy positions, you could create an invisible part that the server updates (This part represents the enemy position). Then you get the client to create the enemy character and “chase” the invisible server part via smooth transition. You will find that the server position will be “jittery”/laggy, but the client will smoothen it out by being slightly behind the server part. By the time the enemy reaches the server part, the server part may have gotten updated to the next position.

To create the “chase” effect, you can use TweenService.

1 Like

I suggest making the client do most of the work, such as visuals and maybe movements/animations while leaving the server to do the damage, spawning, and anything else that the client absolutely can’t touch. Hope this helped if you have any more questions feel free to dm me :slightly_smiling_face:

1 Like