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. https://gyazo.com/c0c1fcdbaf555602f120b7a3c7357d3d
You’re probably handling the AI with individual scripts. I suggest using collectionservice and using a single script to handle all the characters. More scripts eat up more resources.
Roblox usually wouldn’t handle this many humanoids very well, I would assume. Try what @wontbyte said, and if that wouldn’t help, try making a custom character script (Custom health etc).
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:
FallingDown
Climbing
StrafingNoPhysics
Ragdoll
GettingUp
Flying
Seated
PlatformStanding
Swimming
Physics
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.
Also, as said by the others, using a custom humanoid and only adding features that you need will definitely aid in making it more performance-friendly.
I found something weird, you see when I get close to an AI they speed up and work well with performance, but when they are far from me or fighting the opposing AI’s it begins to get buggy.
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.