Cycling through table correctly

So, I’m tryna cycle through a table, but want it to loop through the table in the order that I placed the titles. I’ll place a screenshot and my code below

local creditsTable = {
	["Community Directors"] = {
		310680623,
		525872854,
	},
	["Development Directors"] = {
		109708502,
		168250866,
	},
	["Administration Directors"] = {
		78630005,
		142099293
	}
}
local creditsText = ""
for title, titleTable in pairs(creditsTable) do
	if title == "Community Directors" then
		creditsText = creditsText .. "<b>" .. title .. "</b>"
	else
		creditsText = creditsText .. "\n\n<b>" .. title .. "</b>"
	end
	local info = userService:GetUserInfosByUserIdsAsync(titleTable)
	for _, UserInfo in ipairs(info) do
		creditsText = creditsText .. "\n" .. UserInfo.DisplayName .. "\n<b>(@" .. UserInfo.Username .. ")</b>"
	end
end

creditsHolder.CreditsText.Text = creditsText

image

Hello, here is my attempt, it also allows you to Position the titles however you want. If you have any questions, make sure you ask!

--|< Services >|--
local UserService = game:GetService("UserService");

--|< Variables >|--
local creditsTable = {
    ["Community Directors"] = {
        310680623,
        525872854,
    },
    ["Development Directors"] = {
        109708502,
        168250866,
    },
    ["Administration Directors"] = {
        78630005,
        142099293
    }
}

local titlesOrder = {
    "Community Directors",
    "Development Directors",
    "Administration Directors"
}

local creditsText = ""

--|< Main >|--
for _, title in ipairs(titlesOrder) do
    local titleTable = creditsTable[title];
    if title == "Community Directors" then
        creditsText = creditsText .. "<b>" .. title .. "</b>";
    else
        creditsText = creditsText .. "\n\n<b>" .. title .. "</b>";
    end

    local info = UserService:GetUserInfosByUserIdsAsync(titleTable);
    for _, UserInfo in ipairs(info) do
        creditsText = creditsText .. "\n" .. UserInfo.DisplayName .. "\n<b>(@" .. UserInfo.Username .. ")</b>";
    end
end

creditsHolder.CreditsText.Text = creditsText;

Thank you. Didnt think of this

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