Hi, I have been having problems with my own code that has gotten really confusing for me.
It’s a script where it handles all of the towers and mobs, it runs pretty well and all, until I spawn a bit of zombies… When I spawn a few of zombies, they move fine for about 10 seconds before starting to bug and stop moving.
local Loop = nil
Loop = task.spawn(function()
while true do
for name, tower in pairs(workspace:WaitForChild("Towers"):GetChildren()) do
if script.Towers:FindFirstChild(tower.Name) and tower:FindFirstChildOfClass("Humanoid") then
local humanoid = tower:FindFirstChildOfClass("Humanoid")
if humanoid.Health > 0 then
spawn(function()
UpdateHealth(tower)
require(script.Towers:FindFirstChild(tower.Name)).Main(tower)
end)
end
end
end
for name, mob in pairs(workspace:WaitForChild("Mobs"):GetChildren()) do
if script.Mobs:FindFirstChild(mob.Name) and mob:FindFirstChildOfClass("Humanoid") then
local humanoid = mob:FindFirstChildOfClass("Humanoid")
if humanoid.Health > 0 then
spawn(function()
UpdateHealth(mob)
require(script.Mobs:FindFirstChild(mob.Name)).Main(mob)
end)
end
end
end
task.wait()
end
end)
Forgot to mention, when the mob dies, it’s parent is set to the ServerStorage and put into a folder. Even if I do that, somehow, someway, the loop still runs for the zombie even though it isn’t in the mobs folder.
The module script main function only moves the zombie and makes the zombie attack, thats all it does, it doesn’t have any loops or anything…
If you have any questions about my script, I can answer them.
https://files.catbox.moe/ikqhkg.mp4 – video of the bug.