How to have multiple if conditions happen for the then condition to happen

I’m trying to script a if then statement where if 4 of these parts are destroyed, it then destroys another part allowing the rest of the script to happen
Screenshot 2023-08-09 190000
Here is the part of the script I am struggling with.

5 Likes
if Trash.Trash1 == nil and Trash.Trash2 == nil and Trash.Trash3 == nil and Trash.Trash4 == nil then
   foundtrash = nil
end
6 Likes

I guess I would write this as:

if not Trash.Trash1 and not Trash.Trash2 and not Trash.Trash3 and not Trash.Trash4 then
foundtrash = nil
end

3 Likes

Assuming your “Trash.” variable is an array. You could use a for loop and loop over all the trash → check if all of trash nil → destroy the part

for _, Item in Trash do
      if Item then -- means a trash still exist
             return -- stops rest of code from running if trash exist
     end
end

Part:Destroy() -- if the loop passed it means no trash exist

On mobile and out atm so may be typos/horrible formatting.

3 Likes