How to check if a folder has a certain model/s in it?

I was looking for something where, for example.

Lets say you had a folder named “Mapholder” and every few rounds, a new map goes into that folder with the other being destroyed. If the map or maps had a certain name, for example lets name this map “Factory.”

If the script found anything named Factory, it would make the clocktime 0.

If the script didnt find anything named factory, it’ll make the clocktime 14 or do something else.
It would only do something different if it found certain names, for example if I had 3 maps that I wanted to have this effect, lets name them “Factory”, “Mansion”, and “Shelter”. If the script detected any name in that folder named Factory or Shelter, It’d go dark.

But if it were not to detect anything of the names Factory and Shelter, the clocktime would go day.

What I meant to say was, for example if any amount of maps are in the folder, itll make the clocktime 0, but if they aren’t in the folder, itll make it day. I know how to make the day/night part, but not the part where it will detect if the any amount of maps you can add are in the folder.

2 Likes

I am not too sure what you are looking for here but you can use a FindFirstChild method
Example:

if game.ReplicatedStorage.Maps:FindFirstChild("test1") ~= nil then
      if game.ReplicatedStorage.Maps["test1"].ClassName == "Model" then
               print("Map folder contains test1")
       else
             print("Map folder does not contain test1")
       end
     
else
       print("Map folder does not contain test1")
end
2 Likes
local folder = workspace.Folder

for i, map in pairs(folder:GetChildren()) do
if map.Name == "MAPNAME" and map:IsA("Model")  then
end
end

OR

Similarly like @ forbrad, you could use “:FindFirstChild()”

local folder = workspace.Folder

if folder:FindFirstChild("MAPNAME") then
end

What I meant to say was, for example if any amount of maps are in the folder, itll make the clocktime 0, but if they aren’t in the folder, itll make it day. I know how to make the day/night part, but not the part where it will detect if the any amount of maps you can add are in the folder.

What I meant to say was, for example if any amount of maps are in the folder, itll make the clocktime 0, but if they aren’t in the folder, itll make it day.

use “table.find” to find if there’s a certain value you are looking for in a table.

if table.find(maps, "MAPNAME") then
end

How would I add multiple maps to the “MAPNAME”, I’m not good at with table.find

Are you looking for to see if a table has or no values? the code i showed down checks if the table has any values, if not it just prints “empty table”.

if #maps > 0 then
print("there are values inside")
else
print("empty table")
end
local maps = {"Test1", "Test2", "Test3"}
local MapsFolder = game.ReplicatedStorage.Maps

local function Contains(str)
      if MapsFolder:FindFirstChild(str) ~= nil then
            if MapsFolder[str].ClassName == "Model" then
                  return true
             else
                  return false
             end
     
      else
            return false
      end
end
local HasMap = false
for _,m in ipairs(maps) do
       if Contains(m) then
             HasMap = true
             break
       end
end

if HasMap then 
       --Contains a map inside the map table
else
       --Does not Contain a map  inside the map table
end

I was looking for something where, for example.

Lets say you had a folder named “Mapholder” and every few rounds, a new map goes into that folder with the other being destroyed. If the map or maps had a certain name, for example lets name this map “Factory.”

If the script found anything named Factory, it would make the clocktime 0.

If the script didnt find anything named factory, it’ll make the clocktime 14 or do something else.
It would only do something different if it found certain names, for example if I had 3 maps that I wanted to have this effect, lets name them “Factory”, “Mansion”, and “Shelter”. If the script detected any name in that folder named Factory or Shelter, It’d go dark.

But if it were not to detect anything of the names Factory and Shelter, the clocktime would go day.

I hope this makes more sense

local folder = workspace.Mapholder
local maps = {"Factory", "Mansion", "Shelter"}

for i, map in pairs(maps) do
if folder:FindFirstChild(map) then -- checks if folder, "Mapholder", has any of the maps in the table
print("dark")
else
print("clear")
end
end

OR

local folder = workspace.Mapholder
local maps = {"Factory", "Mansion", "Shelter"}

for i, map in pairs(maps) do
for n, child in pairs(folder:GetChildren()) do
if child.Name == map then -- checks if any of the children of the folder has the names of the maps in the table
print("dark")
else
print("clear")
end
end
end