Ad
Log in to vote
0

How would you skip during a loop without ending it?

Asked by 4 days ago
for i,v in pairs(game.Players:GetPlayers()) do
    if v.Name == hit.Parent.Name then return end
    print(v.Name)
end

Hi this was just an example. I wanted it to make it so that the loop would print everyone's name except for the one person who touched the brick. When I use return end, it just ends the loop altogether. Is there a way so that I can skip that one player while letting the loop continue on?

0
Conditional statements. hiimgoodpack 1424 — 4d

Hi.

Looks like you're using an ad blocker.

That's fine...

No, it really is.

Just, I mean, we put a lot of work into this site, you know?

It would be really really appreciated if you would turn off your ad blocker for our website...

We tried really hard to make our ads as unobtrusive as possible.

If you really hate ads, would you consider a $2 donation via Patreon?

Here's the link.

We love you. We hope you love us too.

.

..

...

Now back to your regularly scheduled Scripting Helpers....

...

..

.

1 answer

Log in to vote
0
Answered by 4 days ago

Your script will nearly work.

It may turn out there is an easier way to do this, but:

for i,v in pairs(game.Players:GetPlayers()) do
    if v.Name ~= hit.Parent.Name then 
        print(v.Name)
    end
end

It skips the one that it hits, but doesn't break the loop.

Ad

Answer this question



Ad