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

How would I set the name of a table to a players UserId?

Ok I know this is a simple thing to do but I don't get the idea of how I can do it

like I've tried this

 BigAssTable = {}

game.Players.PlayerAdded:Connect(function(player)

BigAssTable[player.UserId] = {}
    
    print(BigAssTable.player.UserId)
    
end)

But I get

I want to be able to get tables by players userid

14:06:14.766 - Workspace.Thing:7: attempt to index field 'player' (a nil value)

so for example if a Players UserId was 666

then it would be BigAssTable {

666 = {}

}

and I can use it to do BigAssTable[666]

1 comment

0

I like how you named your table Big***Table, it shows how desperate you are ;))

2 answers

✓ Accepted answer

Your index into the dictionary is fine, the way you're trying to look up your index is wrong.

You were essentially saying "lookup player in BigAssTable and return their UserId". You didn't index the player, you indexed their UserId.

local t = {	}

game.Players.PlayerAdded:Connect(function(NewPlayer)
	t[ NewPlayer.UserId ] = {}
	print ( t[ NewPlayer.UserId ] ) 
end)

I'm not sure if you're trying to change the actual table name or trying to add the Player UserId to the table.

If you want to add the UserId to the table you'd use table.Insert(), like so:

First parameter being the table, second being the value you are inserting.

table.insert(BigAssTable, player.UserId)

I'm not entirely sure if you can change the actual name of the table, and I'm not entirely sure why you'd want to.

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