How would you return with out breaking a loop?

Hi, I’m tryna return a string that indicates if the item is equipped or not but it breaks the loop down - here is with out returning:

here is with returning:


as you can see it stopped looping and do the work.

how would I achieve this?

1 Like

I don’t get how you expect return to work when it is in a for loop?

1 Like

I knew it’s not gonna work, how would I resolve this?

1 Like

The thing though is, I can’t do it outside the loop it self.

1 Like

You cannot run code in the same function after returning. This is an XY problem. Please describe the original problem instead of asking help for something you think is the solution; Running code after returning is not a solution to your original problem.


Certainly. I know what the problem is, I just don’t know how the achieve what I’m trying to do.

1 Like

Make a variable outside the loop and set that to “Equipped”, “Unequipped”.

And return that variable after the end of the outside of the loop. Replace return statements inside the loop with break.

1 Like

If you are trying to print all items and then return one of them, you can save the item you want to return in a variable (that has been declared outside the loop), and return the item after the loop has finished. Example:

local item

for i, v in pairs({10, 20, 30}) do

    if v == 20 then
        item = v

return item

I’m trying to return a string. I’ll try doing what @StrategicPlayZ said first.

1 Like