Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why can't I print the name of the players?

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

function plrs_pls()
	for i,k in pairs(Players) do
		print(k.Name)
	end
end

plrs_pls()

The script is located in ServerScriptService. It's mean to print the name of the players, looping through them. It simply doesn't print anything

Why should it work?

  1. the Players variable is defined.
  2. The for statement is written correctly
  3. The print functions function is written correctly too
  4. The function is called

I also didn't change anything at game services.

I really need help with this. It seems a little bit weird because I can't see any mistake

1 answer

✓ Accepted answer

It's not printing anything because you are getting all the children of players right as the game loads, and since nobody has joined yet, theres no children to Players.

Try this instead:

local Players = game:GetService("Players")

function plrs_pls()
    for i,k in pairs(Players:GetPlayers()) do
        print(k.Name)
    end
end

wait(2)

plrs_pls()

1 comment

0

Thank you! I didn't think about this :))

This discussion is preserved as it was. New answers, comments, and votes are closed.