hey why i cant break this loop please tell me the problem thx you!
function module:FindTarget()
while self.Status == true and self.Number == 1 do
wait(1)
warn("FindTarget Actived")
for i,v in pairs(workspace:GetChildren()) do
if v:IsA("Model") and v:FindFirstChild("Humanoid") and v:FindFirstChild("HumanoidRootPart") and self then
if (self.HumanoidRP.Position - v.HumanoidRootPart.Position).magnitude <= self.Range and v ~= self.Character then
warn("FOUND: "..tostring(v.Name))
module:PlayAnimation()
self.Number = 2
else
self.Number = 1
end
end
end
if self.Number == 2 then
warn("Broke the loop")
break
end
end
end
in Script Editor, click in right position of number line.You can see a red breakpoint. click again to delete it.
When the code runs out of the previous part, the game will pause, 3 windows will open and tell you a lot of things.I have never used them up myself.But just press F5 to get to the next breakpoint, F10 to go to the next line of code.
It’s because you didnt check if self.Number == 1 in the workspace:GetChildren() loop. you only checked in the main while loop. If you need it to stop completely if its found, I suggest changing this from a while loop to a conditional function instead.