#Better way of counting items in a container

23 messages · Page 1 of 1 (latest)

desert nebula
#

is there a quicker way to do this:

        local amount = 0
    for _, v in pairs(player:WaitForChild("PlayerGui").Notifications.Container:GetChildren()) do
        if v:IsA("TextLabel") then
            amount += 1
        end
    end```
full aspen
#

seems fine to me

desert nebula
#

it works yeah i just dont like that its that long

#

@full aspen

vale wadi
#

wdym that long

#

?

desert nebula
#

6 lines

#

like for example

#

in c# its possible in one line,

vale wadi
#

and lua too xd

desert nebula
#

where

full aspen
#

i mean u could also do :GetChildren() and get the length of the table but you also collect things that arent text labels

desert nebula
#

or how

full aspen
#

but other than that u shouldnt care abt how long it is

vale wadi
#
        local amount = 0 for _, v in pairs(player:WaitForChild("PlayerGui").Notifications.Container:GetChildren()) do if v:IsA("TextLabel") then amount += 1 end end
#

this only make the code unreadable

full aspen
desert nebula
#

yeah

#

i was thinking like u said :getchildren

#

and then collecting them from that

#

but that would be the same really

#

i'll jst keep it as it was then

slender anvil
#

Well you can just make a function called like GetChildrensOfClass and return a list of children that have that class, and just get the length of that array.