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

How to get if there is string inside a table?

local Table = {

Value = "String Value";

}

function doStuff(index, value)

end

function recurseTable(tbl, func)
	for index, value in pairs(tbl) do
		if type(value) == 'table' then
			recurseTable(value, func)
		else
			func(index, value)
		end
	end
end

recurseTable(Table,doStuff)

How would I get the string value inside the table?

1 answer

local function LocateFirstAttributeOfType(Table, Type)
	for _, Attribute in pairs(Table) do
		---------------
		local AttributeType = typeof(Attribute):lower()
		if (AttributeType  == "table") then
			---------------
			return LocateFirstAttributeOfType(Attribute, Type)
			---------------
		elseif (AttributeType == Type:lower()) then
			---------------
			return Attribute
		end
	end
	---------------
	return nil
end


local ArbitraryTable = {1, 2, 3, {4, 5, "Six"}}

print(LocateFirstAttributeOfType(ArbitraryTable, "String")) --> "Six"

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