How do I finds the largest integer in a table

I want to find the largest integer in a table, and I’ve tried

 for c, b in pairs(k.Waypointl:GetChildren()) do
 	local maths = math.max(c)
 	print(maths)
 end

I also tried

math.max(unpack(k.Waypointl:GetChildren()))

for more reference “k.Waypointl:GetChildren()” is a table that returns a value 1 - 84, but this is a dynamic value and I need to find the largest integer in this table, how would I accomplish this?

1 Like

do

local m=0
for c,_ in pairs(table) do
    m=math.max(m,c)
end
return(m)
2 Likes

Great Question, this is getting a table of objects, but c also grabs the index # of those objects and that also works for what i’m trying to do, all I need to do now is find the largest integer in that table

1 Like

I’m a bit confused by your setup, but if you want the largest index of the table, you could use the following statement:

 local largest_int = #k.Waypoint1:GetChildren()

Otherwise, I see no need for using math.max in this case due to you iterating over a newly returned table.

4 Likes