Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I make my script not fire multiple times? (Answered)

Asked by 3 years ago
Edited 3 years ago

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
1
at the end of your first if statement, write `break`. that word stops the loop from going any further. Speedmask 661 — 3y
0
@Speedmask THANK YOU! ChirpPerson 74 — 3y

Answer this question