Can I do another for loop in a for loop?

So basically I’m making a round system for my game, and I want to make it so that if it’s a specific game mode it will remove the player from a table I created

if Chosengame == "Battle Tiles" or Chosengame == "Battle Doors" then
					local others = {}
					local finish = ChosenMap:WaitForChild("winpart")
					finish.Touched:Connect(function(hit)

						if hit.Parent:FindFirstChild("Humanoid") then

							local char = hit.Parent
							local player = plrs:GetPlayerFromCharacter(char)

							if player then
								for i, plr in pairs(plrs:GetChildren()) do

									if plr ~= player then
										table.insert(others, plr)
									end
								end				
							end
							for i, Player in pairs(others) do
								if Player.Team == Playingteam then
									
									Player.Team = Lobbyteam
								
                                     --Here's the problem
                                     for i, v in pairs(playing) do
										if v == Player.Name then
											print("we removing him")
											table.remove(playing, i)
										end
									end
									local character = Player.Character or Player.CharacterAdded:Wait()

									local lobbyspawn = game.Workspace.lSpawns:GetChildren()
									local randomlspawn = lobbyspawn[math.random(1, #lobbyspawn)]

									character.HumanoidRootPart.CFrame = CFrame.new(randomlspawn.Position)

									Player.Team = game:GetService("Teams"):WaitForChild("Lobby")

									character:FindFirstChild("Tagged").Value = "nobody"
									character.Humanoid.Health = character.Humanoid.MaxHealth

									local toolstats = Player.ToolStats.Sword.Value
									
									if Player.Backpack:FindFirstChild(toolstats) then

										local plrsword = Player.Backpack:FindFirstChild(toolstats)

										plrsword:Destroy()

									elseif Player.Character:FindFirstChild(toolstats) then

										local charsword =  Player.Character:FindFirstChild(toolstats)

										charsword:Destroy()

									end
								end
							end
						end
					end)

For some reason it won’t loop through the part that I marked where the problem starts, I tried checking if it does the loop by putting a print statement, but it didn’t print it. I don’t know what the problem is and how to fix it as the output doesn’t show any errors

playing is probably empty, I do not see how it is declared in your sample

Try printing what is being checked instead of the loop.

                                     --Here's the problem
                                     for i, v in pairs(playing) do
                                       print(v)  --an actual indication of what v is
										if v == Player.Name then
											print("we removing him") --this only tells you it isn't working, but not why
											table.remove(playing, i)
										end
  		 		  					  end

@gertkeno it’s in for i, Player in pairs(others) do

The issue might be that you are using plr, Player, and player as variables. Maybe change the variable names to a better description.

1 Like

playing ~= player they should be print testing like this, and I’m will to bet it’s empty/nil

--Here's the problem
print(playing)
for i, v in pairs(playing) do

Yes, you can.

for x = 0, 10 do
	for y = 0, 10 do
		for z = 0, 5 do
			print(Vector3.new(x,y,z))
		end
	end
end

I can’t tell what your trying to do with your script.

no it is filled with all the players in the round’s names

Guys I found the solution I’m actually stupid I had to do Chosengame.Name sorry for wasting your time

1 Like

So using the wrong variable then?

Please mark your post as the Solution so people stop trying to solve it over and over. It’ll also help if someone searches the forum to try and find an answer to a similar question.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.