Hello, I’m trying to make a system that will spawn a lot of enemies.
But I dont have any experience in optimizing so I made a simple rig with AI inside of it (AI contains while loop to find a target and chase it). But if spawning a lot of them and game gets really high ping (above 1000 probably). In some games I saw same but with optimized ping.
Anyone can give tips how to make new AI or something that will reduce ping?
ai example:
local hum = script.Parent:FindFirstChildOfClass("Humanoid")
local function tofind()
for i,v in pairs(workspace:GetChildren()) do
if v:FindFirstChildOfClass('Humanoid') and v:FindFirstChild('HumanoidRootPart') and v ~= script.Parent then
return v.HumanoidRootPart
end
end
end
while wait() do
if hum.Health <= 0 then break end
local enemy = tofind()
if enemy then
hum:MoveTo(enemy.Position)
end
end
I know a lot of people have optimized by replacing the old wait() function with the new task.wait(), I think some doubled the number of bots in the game by doing this
That’s the only optimization I know about, but many recommend it, which is why I’m posting this.
not trying to be rude, but I doubt that task.wait can change a lot. Im talking about massive amount of enemies at the same time, its the problem if huge ping, meanwhile in a game that have almost same thing as me doing, there’s no issue about massive amount of enemies increasing ping to 1000+
Never tried using it myself, but maybe CollectionService might be helpful here? In essence, you use it to control a lot of different objects using a single script. Here’s a devforum post explaining how to use it.