GetPlayers() only getting one player

My script is only getting one player, also it is a local script. It’s located in a textbutton, and its only printing one player’s name.

for _,p in ipairs(game.Players:GetPlayers()) do
		
			print(p.Name)
end

so how many players are in game?

How are you testing the game? Like you host a Server where you Control 2 Clients or just normal testing?

My Bad. I have not thought about this well enough. That loop only loops through the Players once, then it does not loop anymore. The fix could just be putting it into a function:

local function PlayerJoined()

	for _,p in ipairs(game.Players:GetPlayers()) do
			print(p.Name)
	end
end

game:GetService("Players").PlayerAdded:Connect(PlayerJoined)

oh my bad, i should’ve shown more explaining. The loop runs every time the textbutton gets activated.

I’m testing by controlling 2 clients.

You could try in pairs() instead of ipairs()

it still did not work with in pairs()

ok nevermind i did something and i managed to fix it.

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