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

How can we print out local from an Table?

Let's say we create an table and we want to print out our name from all of those other people on the table. For example their is 3 players : Alvin,Bob,Dave and my name is Dave so with an table how can we print out our name locally when i play it should say Dave

local AllPlayers = {}
for i,v in pairs(game.Players:GetPlayers) do
 table.insert(AllPlayers,v)
-- What more to add so we can print out the name
Print()
end)

2 answers

Rather than adding the players into the table in a for loop, it might be easier to just say:

local AllPlayers = game.Players:GetPlayers()

In your for loop you could then say:

for i,v in pairs(AllPlayers) do
	Print(v) --V references the value of the specific entry in the table.
end)

A lot of things here are being done incorrectly.

For example, you are using multiple tables to achieve something that only requires a simple loop. You aren't actually calling the GetPlayers function.

Here is a quick fix that is also as compact and neat as possible.

for i,v in pairs(game.Players:GetPlayers()) do
	print(v.Name)
end

1 comment

0

Yup, that sounds good! Guess that’s what happens when I don’t test code before posting it.. XD

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