For i,v pairs Loop Ignore certain things in a folder?

For some reason it kept printing “1” This is what the script looks like.

while task.wait() do
for i,v in ipairs(workspace.FolderWork:GetChildren()) do
		local ignored = {'Part'}
		local parts = {}
		if not table.find(ignored,v.Name) and not table.find(parts,v) then
			table.insert(parts,v)
			print(#parts)
		end
	end
end
		local parts = {}
while task.wait() do
for i,v in ipairs(workspace.FolderWork:GetChildren()) do
		local ignored = {'Part'}
		if table.find(ignored,v.Name)  then return end
        if table.find(parts, v) then return end
			table.insert(parts,v)
			print(#parts)
		end
	end
end

It didnt really print anything out! I forgot to mention that when the player walks near the part it will be named close and when they are far away it will be called part again!

U should use Magnitude and RunService to detect if the player is close and change the text from there

Im not sure if I sayed it correctly! I was trying to say Ive added that already I just want the script to know how much parts that are called Close are in there!

local parts = {}
while task.wait() do
for i,v in ipairs(workspace.FolderWork:GetChildren()) do
		local ignored = {'Part'}
		if table.find(ignored,v.Name)  then return end
        if table.find(parts, v) then return end
        if v.Name ~= "Closed" then return end
			table.insert(parts,v)
			print(#parts)
		end
1 Like

ive added that and it still didnt print anything

Please try this. Hope this works how you want.

local FolderWork = workspace.FolderWork
local blackList = {"Part"}

local CloseCount = 0 -- Count for "Close" part
while task.wait() do
     for _ , partChild in pairs(FolderWork:GetChildren()) do
             if table.find(blackList, partChild.Name) ~= nil then
                   continue   -- Skip this iteration, move on to the next one.
             end

             if partChild.Name == "Close" then
                   print("Find 'Close' Part!")
                   CloseCount = CloseCount + 1 -- Add the count
             end
     end
     print("Current 'Close' part in Folder" .. CloseCount)
     CloseCount = 0 -- This value resets once the loop is done, it will give you an actual count of 'Close' part.
end

return

This will completely exit from the loop, that is why it does not print anything.

Thank you guys! This really improved my game ALOT

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