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

Printing the end value of a table?

Hi. I was trying to create a table (named playerlogger) and would insert each player in a game into the table after a certain amount of time. The problem is that with using the method print(playerlogger[end number]) is that I don't know how many players there could be in-game.

If I do something like print(playerlogger[8]) then there couldnot be 8 players in game, so what would I do?

2 comments

2

print(playerlogger[#playerlogger])

0

it works, thanks!

2 answers

Using the # operator you can get the amount of members a table has, let's say you have this table t = {"pizza", 2, false}, in this case ``#t` will return 3 since we got 3 members, and logiclly doing t[#t] will return the last member of the table since its index will be the same as the number of the table's members.

local playerlogger = {"plr1", "plr2", "plr4", "plr6"}

print(playerlogger[#playerlogger])

i hope you got the idea!

2 comments

0

I already said that but ok

0

sorry this answer was too ez that i had to answer it xd

First of all, get the amount of players in the server using a for loop and a variable. Second, you wanna do print(playerlogger[amountofplayers])

2 comments

0

You just need to do #table. No need to do for loop.

0

I mean, he can, but i'd rather use arrays, no need to down vote this as it is another way if he doesn't know how to use arrays.

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