Optimization problem

Sup guys, i want to optimize my TD game but i have no ideas how to do this.

What is the problem? Problem with ping because of massive zombies animation and movement. And also fps dropping because of the big zombie amount.

What i have been tried? I do task.spawn functions for multi-threading but it doesn’t work fine with big amount of zombies.

There’s a screenshot of my problem:
image
image

It is multi-threading, but there’s still only one thread running at a time. With parralel lua, you can actually have multiple threads running at once. This might not make lag better for the server though.

task.delay(0.25, function()
    while true do
        -- Lua never leaves this thread
    end
end)

task.delay(0.5, function()
    print("Success!") -- Never printed
end)

There’s a few things to try:

  • Trust the client to create and animate NPCs, but the server handles everything else about the NPC
  • Less data with each NPC
  • More efficiently handle NPC movements
  • Less NPCs, please
1 Like

Well. I don’t know what you have already done. But here are some suggestions.

  1. Try spawning all the zombies on the client. Have server say where when they spawn and plan the route. They also will probably need an ID so that you can talk about specific zombies easier. This can reduce network traffic by quite a bit since you can compress the information a lot more.

  2. If possible remove the humanoid. That comes with some extra processing if I recall correctly and managing to make the zombies without it might speed it up. Also anchor the zombies and move them by CFrame directly.

  3. Do you need to draw every zombie? I’d experiment with ways to get away with not updating zombies and potentially not even drawing some of them. (When the zombies are that dense you might be able to get away with only drawing 2/3 or 1/2 of the zombies (though this would be tricky since you need the last zombies to always be drawn so you either need to ensure the invisible ones get targeted first or that they get drawn when density gets low enough but that could lead to a pop in. you could also try just drawing the head of those zombies instead of making them invisible and give them the rest of a body when density lowers)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.