#Help please. Game freezing for .1 sec when deleting npc is character

1 messages · Page 1 of 1 (latest)

granite dirge
#

Only freezes when deleting first npc
I have tried:
for _, chl in pairs(char:GetChildren()) do if #chl == 0 then char:Desroy() end chl:Desroy() task.wait(.1) end

And created Chache Folder:
`local CacheFolder = game:GetService("ReplicatedStorage").EnemiesCache
local CacheSize = 50 -- objects

while true do
if #CacheFolder:GetChildren() >= CacheSize then
for _, el in pairs(CacheFolder:GetChildren()) do
el.Parent = nil
task.wait()
el:Destroy()
task.wait()
end
end
task.wait()
end`

But still freezes

lime flame
#

this will help

granite dirge
#

I am killing them before deleting, so their health is 0, and Anchoring them did not helped too. Still Freezing

#

By the way, they are moving (MoveTo()), then I am killing them, then deleting

true ocean
#
granite dirge
#

I am deleting Npc is character

true ocean
granite dirge
#

Ohh yes I have script in it

#

But wait, when I was deleting every children in the npc is character it deleted everything, but then I deleted whole empty character its still freezed

granite dirge
#

Ok

#

If I am in studio deleting Animation script, then running the game, deleting char and it is not freezing

true ocean
#

You can modularize your npcs so they don't need scripts in them

granite dirge
#

Ok

mortal idol
#

Or use AI and make ur life 100x better

true ocean
wheat knoll
#

try disabling the script(s) first, that way maybe it doesn't cause a lag spike.

wheat knoll
#

Cool, remember to mark the post as solved