Ad
Log in to vote
0

How would you skip during a loop without ending it?

Asked by 1 year 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 1842 — 1y

1 answer

Log in to vote
0
Answered by 1 year 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