I'm trying to construct a piece of code that checks folders' children for a ClassName match (If a child within a folder is a decal). I wanted to make a piece of code that checks if the folder contains a decal; if the folder contains a decal, it would print ("Image found!"), if it did not work, it would print ("Image not found"). My problem is that while it somewhat works, it checks all the children and fires off multiple times. I only want it to fire off once and only if it found the decal or not. How do I fix it?

If any additional clarification is needed, please don't hesitate to ask me. All help is appreciated!

local folderImage = folder:GetChildren()
for i=1, #folderImage do
	if folderImage[i].ClassName == "Decal" then
		print("Image found!")
		selectionImage.Image = (folderImage[i].Texture)
	elseif folderImage[i] ~= "Decal" then
		print("Image not found")
		selectionImage.Image = "http://www.roblox.com/asset/?id=2621877628"
	end
end

2 comments

1

at the end of your first if statement, write break. that word stops the loop from going any further.

0

@Speedmask THANK YOU!