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

How do you get the last value in a table?

Hi there, I'm not too good with tables and I am trying to figure out how to get the last value in the table? I already have a script that sets the table up. Basically I'm trying to get the last value from the table and set a text box to say the value that is displayed. The table is full of strings. Thanks :)

Table name is "Stations"

5 comments

0

if it is an array, you can use the length operator to get the length of the table, and then use that to get the last value in an array. Ex: array[#array]

0

so something like TextBox.Text = Stations[#] ?

0

Stations[#Stations]

0

^

0

Thank you, Stations[#Stations] worked perfectly :)

1 answer

✓ Accepted answer

Just use the unary operator, #.

local t = {"a","b","c","d","e"}

print(t[#t]) --> "e"

2 comments

0

dang it... i was gonna say this... but goojob!

0

:))

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