Im trying to make this script print the names of all players in the game please help!
for i, v in pairs(game.Players:GetPlayers()) do
print(i)---player priority
print(v)---players name
end
Im trying to make this script print the names of all players in the game please help!
for i, v in pairs(game.Players:GetPlayers()) do
print(i)---player priority
print(v)---players name
end
game:GetService("Players").PlayerAdded:Connect(function()
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
print(v.Name)
end
end)
when someone joins the game you make a loop through all the players and print their names
I think putting Player Removed would also matter.
it keeps saying Player is not a valid member of DataModel
so the service is renamed, also poke no it doesnt matter
script updated so it works no matter what name the service has
@Gameplayer365247v2 it actually does. The person asking the question is probably using this code to get an up-to-date list on the players. So adding a function for a player removed event DOES matter.
Instead of using an in pairs loop, I would print them in a table so it's easier to read. Here
local playerService= game:GetService("Players")
local playerTable= { }
game.Players.PlayerAdded:Connect(function(player)
table.insert(playerTable[player.Name])
end
game.Players.PlayerRemoved:Connect(function(player)
table.remove(playerTable[player.Name])
end
while wait(15) do
print("playerTable")
end
Your Script is also giving me the Player is not a member of datamodel
completely unnessesary, you dont need to insert any names into a table, just need to loop through the player list
:(
I was thinking about ram usage, so using tables would reduce how much ram would be used. Ram usage is actually kinda important when you're making actual games to improve user experience, but whatever.
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
also quick comment, printing i, i believe wont do anything since i in this case is the Players service which apparently is renamed