Checking if a string value is in a folder

Hello! I am seeking help with making a script that checks if a value is inside a folder before doing something. Whenever a user presses a button on a gui, it moves one of the values into the folder (in order value 1, value 2, value 3 …) . I don’t want them to be able to click the second button until it checks that the first value is inside the folder

local folder = game:GetService("Workspace").CountryData.Jamaica.Technology.Slots

for i, v in pairs(folder:GetChildren()) do 
   if v:IsA("StringValue") then
       print(v)
   end
end 

This simply prints a list of the values inside of the folder, how would I check if a value was inside the folder?

if folder:FindFirstChildWhichIsA("StringValue") then 
print("stringvalue yay")
end

When putting the values there you should name them “1”, “2”, etc.
Then simply check if it is in the folder using folder:FindFirstChild(tostring(A_NUMBER))

there’s multiple ways to go about this, if the folder only has these stringvalues, you can check the number of children

if #Folder:GetChildren() >= RequiredAmount then
print("yes")
end

you could also just search by name

if Folder:FindFirstChild("RequiredValue") then
print("yes")
end
1 Like

this works great! Any ideas on how I could make this a loop where it continuously checks the folder until the value is there and then it stops?

you can use Folder.ChildAdded:Wait() to infinitely yield until an object is added to the folder without needing connections