How to name a table with the player's UserID on the server

This is for a Tower Defense game. I intend to add teleportation for a group of people who can join the servers created by a player.

When a server is created, I’ve coded it to fire a remote event and I would like to create a table of the players that joined that specific server.

The problem is I don’t know how to name a table with the players UserID/User Name.

image

I have the players UserID, User Name (as above) but I can’t type the below code as it changes the value of the variable and doesn’t set the name of the table.

     CSR.OnServerEvent:Connect(function(Player, UserID, UserName)
          local UserID = {}
     end)

I know this might be really easy or badly explained but I’m new to developing so I’m not really sure about a lot of stuff.

yeah you cant name variables like that. just make another table and put it in there

 CSR.OnServerEvent:Connect(function(Player, UserID, UserName)
          local playerTable= {}
playerTable[UserID] = {}
     end)
1 Like

I didn’t understand what your trying to say. Do I make a table in a table?

yeah so my code will make a table called playerTable - this table will hold other tables indexed by userID.
so to access them you first call the playerTable and then the userId index.

playerTable = {
 [1019161715617] = "floop",
 [2827262726] = "Boop".,
}

so playerTable[1019161715617] is the string “floop”

Thanks for the quick response and clarification. I’ll mark your answer as the solution.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.