Soo i have this script, it creates thread for enemy moving in tower defense game:
local Thread = task.spawn(function()
while self.Moving do
local Node = self.Path[self.CurrentNode]
local NextNode = self.Path[self.CurrentNode + 1]
if not NextNode then
VACC:Clear(self)
return
end
local Time = (NextNode - Node).Magnitude / self.Speed
self.Position = Node:Lerp(NextNode, self.CurrentNodeTime/Time)
self.Part.Position = self.Position
self.CurrentNodeTime += task.wait(Frequency)
if self.CurrentNodeTime > Time then
self.CurrentNodeTime = 0
self.CurrentNode += 1
end
end
return
end)
Question is, if i call Enemy:Stop() from main script, and self.Moving will be set to false, will this thread be Garbage Collected or not?