Can't get players with for i,v in pairs

I don’t know if i have mispelled something, i have a script that gets the players currently playing:

local Players = game:GetService("Players")
Players = Players:GetChildren()

wait(20)
print("Yes")
for _, Player in pairs(Players) do
	print("1-1")
	local Playing = Player:FindFirstChild("Playing")
	if Playing then
		print("2-1")
		if Playing.Value then
			print("3-1")
		end
	end
end

I added a wait so the players can take time to join and not check when there’s no player in the server yet. So, i added some prints to debug, because the script didn’t find any player, for any reason, it only printed “Yes”, but not the other prints, there’s not even an error, I don’t know what i did, i see everything normal for me, thanks for reading.

Try game.Players:GetPlayers() instead of GetChildren(). Seems like the latter is not returning anything above 0. Or, instead of having a variable, just put in game.Players:GetPlayers() near the pairs. It will give a more up-to-date table of players.

2 Likes
   for _, player in ipairs(game:GetService("Players"):GetPlayers()) do
     
   end

:GetPlayers() returns only player objects.

there’s no necessity to iterate using the pairs function when you aren’t using the index (_, players)

Did what people have said to you work?

And, try this code:

local PlayersFolder = game:GetService("Players")
Players = PlayersFolder:GetPlayers()

wait(20)
print("Yes")
for _, Player in pairs(Players) do
	print("1-1")
	local Playing = Player:FindFirstChild("Playing")
	if Playing then
		print("2-1")
		if Playing.Value then
			print("3-1")
		end
	end
end