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

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

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

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

4 comments

0

When I tried printing it, the errors fixed (most errors you put on the script was easy to fix) but it just prints {}

0

I also meant as a named value.

0

Can you tell me what are you trying to achieve, Why do you even want a named value there?

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).

Easy

local plrs = {}

for i, player in pairs(game.Players:GetPlayers()) do
	if player then
		table.insert(plrs,player)
	end
end

1 comment

0

I meant instead of a number, it should be a nammed variable in a table.

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.

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