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

how to make a table just for that player when the players join?

what i tried :

local friends = {  }
game.Players.PlayerAdded:connect(function(plr) 
	local table2 = plr.UserId

im trying to make a table for the player's friends (they add in game, different from roblox)

right now i have it as one whole table. so everybody has the same friends. is this even possible?

1 answer

✓ Accepted answer

All you have to do is create a nested table using the player object as the key.

local friends = {};
game.Players.PlayerAdded:Connect(function(plr) --// connect is deprecated, use Connect instead. 
	friends[plr] = {};
end);
game.Players.PlayerRemoving:Connect(function(plr)
	--// Do any necessary cleanup
	if friends[plr] then
		friends[plr] = nil;
	end;
end);

Hope this helped.

Read more on tables here.

7 comments

0

are you serious? why does roblox do that? xD its the same thing aint it?

0

No, this creates new tables as values. Your example is only one table.

0

its saying "10:55:43.608 - Workspace.FriendsDataStore:30: bad argument #1 to 'pairs' (table expected, got nil)" this is line 30: for key, value in pairs(friends[plr]) do

0

and i meant about "connect" > "Connect"

0

My guess is that you're using 'plr' in outside of the event, which obviously wouldn't work

0

i fixed it thanks :D

0

just had to move some stuff around a few lines. thanks for letting me know about connect also. 

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