Hello, I’m trying to make a table for each character. I already tried searching up on devforum, but I’m unsure how to do it with
table.insert
For example,
local playerBoat = {}
local Assets = {
Epic = object;
Cool = object;
}
table.insert(playerBoat, {player = Assets})
print(playerBoat)
So I want it to print like SilentSuprion…Epic and Cool.
Sorry for my poor explanation I don’t how to describe it. Basically think of it like a table inside a table inside a table. lol.
You can still use player as an index, but you are storing a lot of unnecessary information using that as an index (i.e. the WHOLE player instance) just use a number as an index when you can.
Just make sure to remove the value once they leave the game.
Players.PlayerRemoved:Connect(function(PLayer)
playerBoat[Player] = nil
-- The index will be removed once the value is set to nil.
end)
As for making individual tables on characters, that depends on how you arrange the tables.
In this case, i suggest just directly giving it the Assets table as the value, as shown on my last example, since giving a table with player as their only index is wasteful.
On the printing side, use table.foreach as dduck5tar said, but also add an identifier on which data you’re printing off from.
for Player,Data in next,playerBoat do
print(Player)
table.foreach(Data,print)
end
-- Output:
-- SlientSurpion
-- Epic object
-- Cool object
You can go as deep as you want with table->table->table->ad infinitum. There is no limit. It just takes horribly readable code to access the deepest members. There are better and much more readable and understandable ways to do it.