Can I do this with my table?

I am trying to assign a color to items with certain rarities.

Currently the only thing I tried was this, because I couldn’t think of anything else.

Piece of script in question:

local rarities = {
	["Common"] = 179, 179, 133;
	["Rare"] = 249, 183, 60;
	["Epic"] = 193, 61, 198;
	["Legendary"] = 65, 94, 198;
	["Unobtainable"] = 208, 208, 208;
	["Event"] = 198, 41, 41;
}

local newSkinBox = shopFrame.SkinTemplate:Clone()
		local rarityValue = skin.Rarity.Value -- This is the value that indicates what rarity a certain skin is.
		local skinRarity = newSkinBox.Details.Rarity -- This is a frame that I am trying to assign the color of rarity to.
		
		skinRarity.BackgroundColor3 = Color3.new(rarities[rarityValue])

This is the result my script gives:

dear god…

local rarities = {
	["Common"] = Color3.fromRGB(179, 179, 133);
	["Rare"] = Color3.fromRGB(249, 183, 60);
	["Epic"] = Color3.fromRGB(193, 61, 198);
	["Legendary"] = Color3.fromRGB(65, 94, 198);
	["Unobtainable"] = Color3.fromRGB(208, 208, 208);
	["Event"] = Color3.fromRGB(198, 41, 41);
}

skinRarity.BackgroundColor3 = rarities[rarityValue]
1 Like

Thanks for this eye-opening comment, I forgot this was a way haha

1 Like

If you didn’t know, this is essentially what your table looked like to roblox:
image

A comma in tables is what luau uses to separate values. Tables are allowed to have any key/index, which is why after the first comma you used started to insert to numbered indexes instead. A semicolon is a conveniency with luau, since multiple statements can already be declared on the same line, so the semicolons in your code were doing nothing

Ohhhh I see, thank you for this insight

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