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

Is it possible to create a table for a specific player without doing the following?

local Table1 = { }

game.Players.PlayerAdded:connect(function(player)
Table1[player] = { }
end)

or

--In ModuleScript

local Table1 = { }



return Table1

The reason I ask this is because the for loop I'm using doesn't recognize the tables in both of those ways, I can't think of a different way to create a table specifically for the player, without using their ID which doesn't work:

local player.userId = { }  --Expected identifier got, '.'

If it is possible how so?

3 comments

0

Make a different table for each player in the table itself.

0

Also consider using datastores.

0

Is that not what I have in option 1, a table for each player in a table? Also, I don't really want to use datastore because it's only a temporary thing, I'm OK with it being deleted after the player leaves.

1 answer

✓ Accepted answer

By what it sounds like you're trying to do, no, there's not.

The issue with tables is of course that they are just value holders. You'd have to give extra context to fully understand what you wanted to get from it of course, but you also need to consider why your loop doesn't recognise them.

Perhaps you should try using pairs() to iterate through tables?

2 comments

0

I did use ipairs(), it just does not seem to think the table holds anything, I will find another way to do what I want, thank you.

0

Use pairs(); never use ipairs, as it is slower than any other practical alternative.

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