I created a game where you have a army of allies with swords facing an army of enemies with swords. Problem here is, when the game is in motion it stutters and everything starts to move slow, the Server especially.
And when they respawn, it’s even worse.
Anyone know how to stop this and speed the game up?
Humanoids by nature are fairly expensive. In this case, you’re going to want to look at two optimisation practices. You’re going to want to reduce server memory usage (or reliance on the server) and lighten the expense of humanoids.
In terms of reducing server memory usage, that’s just a question of what needs to be on the server and what the client can handle. You also must think about the way you’re handling what you have - for example, you can allow for a single script to control multiple NPCs.
In terms of lightening Humanoid expense, one of the ways you can do is by disabling state types you do not need. I obviously can’t speak for you, but a brief look at your Gif makes me believe that you can disable the following states with no future trouble:
There are other ways, but I’m not quite aware of them.
Unfortunately, fact of the matter is that Humanoids suck. If disabling Humanoid states and optimizing your server don’t allow you to manage the number of characters your game requires, you might want to look into implementing your own character controllers without using Humanoid instances.
eg. One script or a hierarchy of modules manages creation / deletion / AI / animation / data (ie. health) for all characters, BodyGyro and BodyVelocity moves characters, raycasting or collision detects attacks, and BillboardGUI displays nametags and health bars. Not sure if playing animations on these characters exclusively locally is worthwhile, someone else could probably say for sure.
Alternatively, you might be able to still use Humanoids for health tracking and some other conveniences if you disable as much as you can and set them to PlatformStand, implementing everything else yourself. But there’s a limit to what you can gain from doing this.
I can’t see a way completing the task I want without Humanoid Instances. I also noticed when the game runs it doesn’t slow down until the opposing AI’s start to collide, firing off many scripts such as the Respawn, Damage, Swords etc.
Perhaps you could show an example without you using Humanoid Instances?
It depends on how taxing your scripts are. Presumably, based on what you have showed us, you could have some sort of loop that detects or finds specific enemies to attack. More loops = the worse it gets.
If you still haven’t, I suggest you doing every single visual in the client. Only do the most important things on the server.
I believe Theme Park Tycoon 2 only has one script that controls all the AI.
Probably another optimisation issue. That pertains to network ownership. I assume that OP is not setting network ownership so it’s being automatically handed to the client when near and by the server when not.