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

How would I get the last children in a folder?

So I've been wanting to know this question for a bit.

I've made a folder with 5 models in it.... and I wanna know how I could get the last model name in that folder with a script... Is this possible? if so how?

2 comments

0

Please be more descriptive about your problem.

0

BazementBoyz, you're on a roll with not reading the question xD

1 answer

✓ Accepted answer

If you're familiar with arrays, then you should be aware of :GetChildren(). Since this function returns a collection of the Instance's children, we can address it formally as an array.

It's sensible enough to assume that the last attribute would reside at the last index in a table. Therefore, all we have to do to allocate said last attribute is determine this index. Fortunately, there is no difficulty to this task, as the last index in question is actually numerically relative to the array's size; since ROBLOX's arrays are one-based.

local Models = Models:GetChildren()

local LastModel = Models[#Models]

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