Get table of property from children

How can i get a table of a property of many instances? for example, a function like
GetChildrenProperty(Children,"ZIndex") and it returns {1,2,3,4,5}

I don’t know how to start, all i pretty much want is get the max number from the ZIndexes table so i can apply the ZIndex to make an UI show in front of the others.

If you just want the biggest ZIndex, this should work.

local biggestZIndex = 0
for _, child in parent:getChildren() do
	if child.ZIndex > biggestZIndex then
		biggestZIndex = child.ZIndex
	end
end

If you want to first store the ZIndex values in an array like you wrote in your post and then get the highest one, then this should work.

local function getPropertyValuesOfChildren(parent, propertyName)
	local propertyValuesOfChildren = {}
	for _, child in parent:getChildren do
		table.insert(propertyValuesOfChildren, child[propertyName]
	end
	return propertyValuesOfChildren
end

local biggestZIndex = 0
for _, zIndex in getPropertyValuesOfChildren(parent, "ZIndex") do
	if zIndex > biggestZIndex then
		biggestZIndex = zIndex
	end
end

Thanks, i’ll try it and see if it works

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.