Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can we print out local from an Table?

Asked by 4 years ago

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

Log in to vote
1
Answered by 4 years ago

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)
Ad
Log in to vote
0
Answered by 4 years ago

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
0
Yup, that sounds good! Guess that’s what happens when I don’t test code before posting it.. XD lincol92008 46 — 4y

Answer this question