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

How do I add a table that includes a players name?

Asked by 3 years ago

I tried this

local list = {}
list.tostring(game.Players:GetChildren()[1].Name) = "Good"
print(list)

and it gave me an error Workspace.Script:2: Expected identifier when parsing expression, got '=' How would I get a players name on that table? NOTICE:The server is only a single player server so if you were asking me to use localscript, here is my awnser back.

3 answers

Log in to vote
0
Answered by
Borrahh 265 Moderation Voter
3 years ago

Hey Mate, Since it's a 1 player game, you could insert them into the table, when they join the game!

local list = {}
game.Players:PlayerAdded:Connect(function(player)
    table.Insert(list, player.Name)
end)

If you want to add the Player itself, just remove the .Name

0
When I tried printing it, the errors fixed (most errors you put on the script was easy to fix) but it just prints {} tamasjonas 62 — 3y
0
I also meant as a named value. tamasjonas 62 — 3y
0
Can you tell me what are you trying to achieve, Why do you even want a named value there? Borrahh 265 — 3y
0
I meant a custom name instead of a number. Also, it might be useful for my adminship requester that used Datastores instead of HTTP Requests(Mainly because I don't have discord and I don't have a domain). tamasjonas 62 — 3y
Ad
Log in to vote
0
Answered by
MattVSNNL 620 Moderation Voter
3 years ago

Easy

local plrs = {}

for i, player in pairs(game.Players:GetPlayers()) do
    if player then
        table.insert(plrs,player)
    end
end
0
I meant instead of a number, it should be a nammed variable in a table. tamasjonas 62 — 3y
Log in to vote
0
Answered by 3 years ago

Nevermind I found how to set a named variable in a list, you may close this now. I may as well say that all the awnsers posted here did not tell me how to set a nammed variable in the list. My code:

local list = {}
wait()
list[game.Players:GetPlayers()[1].Name] = "Hi"
print(list)

Well, too late to reply.

Answer this question