Script continue to run when no NPC humanoid in workspace?

I don’t really know how to shorten it but
The script go through some lines then it suppose to hit this barrier that only opens again after all NPC humanoids are gone then continue through it

The code just kept randomly “true” “false” multiple times instead of doing its thing

local db = true

while db == true do
for i,v in pairs (game.Workspace:GetChildren()) do
		if v:FindFirstChild("Humanoid") and not v:FindFirstChild("Plr") then
			db = true
			print("true")
		else
			db = false
			print("false")
		end
		wait(1)
	end
	end

I tried script disabling and re-enabling but it just restart the script and looking for other forums but it didn’t do anything with humanoids

Any help is thanked :+1:

1 Like

Because every object in the workspace doesn’t contain humanoid. And when db is false, your while loop stops running.

When it comes to your script runs when no humanoid is there, it’s because db is true, so it runs, when it doesn’t find humanoid, the while loop stops.

2 Likes

Here is my solution if other people came across this:

local db = true

while db == true do
for i,v in pairs (game.Workspace:GetChildren()) do
		if not v:FindFirstChild("NPC") and v:FindFirstChild("Plr") and v:FindFirstChild("Humanoid") then
			db = false
			print("false")
		else
			print("true")
		end
		wait(1)
	end
	end

Thanks @Moneypro456789

1 Like

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