How to use for loop to set GUI text to a random item in a 2D table?

Hello, I have a StringValue that has a certain rarity that gets set by random. Say this time around the rarity is ‘Legendary’.

Now I have a TextLabel that is supposed to reveal what item you got as well as the rarity of this item (via Colors)

My problem is actually getting the game to choose an item for me. I have this 2D array that looks like this:

local Rarity = script.Parent.Parent.Rarity
local Items = {
	Common = {
		"Wood",
		"Stick",
		"Stone",
		"Dirt",
		"Ore",
	},
	Uncommon = {
		"Sulfur",
		"Copper",
		"Coal",
		"Glass",
	},
	Rare = {
		"Rust",
		"Bronze",
		"Iron",
		"Aluminum",
	},
	Epic = {
		-- pls give ideas lmao
	},
	Legendary = {
		"Gold",
		"Diamond",
		"Sapphire",
		"Emerald",
		"Ruby",
		"Amber",
	},
	Mystic = {
		-- pls give ideas lmao
	}
}

Ok now the localscript needs to set the textlabel to those items, so I did:

for i, v in pairs(Items) do
	if i == Rarity.Value then
		local randomItem = math.random(1, #i:GetChildren())
		script.Parent.Text = Items[i][randomItem]
	end
end

But it did not work. Any help please?

Btw this is outcome
image

local subItems = Items[Rarity.Value]
local randomItem = subItems[math.random(#subItems)]
script.Parent.Text = randomItem

where do i put that, in the for loop?

no you don’t need to loop

like this

local Rarity = script.Parent.Parent.Rarity
local Items = {
	Common = {
		"Wood",
		"Stick",
		"Stone",
		"Dirt",
		"Ore",
	},
	Uncommon = {
		"Sulfur",
		"Copper",
		"Coal",
		"Glass",
	},
	Rare = {
		"Rust",
		"Bronze",
		"Iron",
		"Aluminum",
	},
	Epic = {
		-- pls give ideas lmao
	},
	Legendary = {
		"Gold",
		"Diamond",
		"Sapphire",
		"Emerald",
		"Ruby",
		"Amber",
	},
	Mystic = {
		-- pls give ideas lmao
	}
}

local subItems = Items[Rarity.Value]
local randomItem = subItems[math.random(#subItems)]
script.Parent.Text = randomItem

why doesn’t it work on localscript? ill try with regular script in a min
edit: worked on script.

maybe in a localscript you have to waitforchild when getting the Rarity instance

Don’t use a server script to manipulate a client’s user interace, that’s an unnecessary waste of resources, you may need to use ‘WaitForChild’ as suggested in order to wait for one or more objects to replicate/load.

alright, ill go ahead and try that soon.