Unable to assign property BackgroundColor3. Color3 expected, got nil

I’m trying to set the color for different objects based on their rarity but i keep getting this error
“Unable to assign property BackgroundColor3. Color3 expected, got nil”

here is a snippet

--Colors Values
local commonColor = Color3.fromRGB(81, 81, 81)
local uncommonColor = Color3.fromRGB(47, 162, 65)
local rareColor = Color3.fromRGB(35, 185, 208)
local epicColor = Color3.fromRGB(115, 0, 172)
local legendaryColor = Color3.fromRGB(241, 133, 9)

local TextcommonColor = Color3.fromRGB(120, 120, 120)
local TextuncommonColor = Color3.fromRGB(52, 195, 57)
local TextrareColor = Color3.fromRGB(23, 255, 236)
local TextepicColor = Color3.fromRGB(170,0,255)
local TextlegendaryColor = Color3.fromRGB(241, 197, 19)

local rarityColors = {commonColor, uncommonColor, rareColor, epicColor, legendaryColor}
local rarityTextColors = {TextcommonColor, TextuncommonColor, TextrareColor, TextepicColor, TextlegendaryColor}
local rarityName = {"COMMON", "UNCOMMON", "RARE", "EPIC", "LEGENDARY"}

local function setRarity(rarity)
	local color = rarityColors[rarity]
	local textColor = rarityTextColors[rarity]
	promptGui.Bottom.BackgroundColor3 = color
	promptGui.Top.Divider.BackgroundColor3 = color
	promptGui.Bottom.Rarity.TextColor3 = textColor
	promptGui.Top.WeaponName.TextColor3 = textColor
	promptGui.Bottom.Rarity.Text = rarityName[rarity]
end

What are you passing to setRarity when you call it? From the looks of it, you need to pass in a number from 1-5 since that’s the range of the tables you have.

You’re probably thinking you can pass in a string rarity from what I can guess, you need to use a dictionary in that case

1 Like

Show us the part where you call the setRarity function

I’m running the setRarity in the promptshown function because i’m trying to make a custom proximty prompt

proximty.PromptShown:Connect(function()
	local promptGuiClone = promptGui:Clone()
	promptGuiClone.Parent = promptGuiClone.Adornee
	promptGuiClone.Bottom:TweenSize(UDim2.new(0,200,0,30), "Out", "Bounce", .3, true)
	promptGuiClone.Top:TweenSize(UDim2.new(0,200,0,60),"Out", "Bounce", .3, true)
    setRarity(proximty:WaitForChild("RarityString").Value)

end)

The rarity string will NOT get the actual color since the names don’t exist in the table.

Here is a picture
image

Again most likely you’re passing in a string for setRarity judging by the name of the value, that doesn’t work since you made tables instead of dictionaries, so you need to pass in a number

A simple fix is to make the tables where the setRarity function was made into dictionaries

Example in case you may not know how dictionaries work

local rarityColors = {
     Common = commonColor,
     Uncommon = uncommonColor,
}

So i change my variables into a dictionary also do dictionaries work like in python?

1 Like

Ya, they are fairly similar, except table.append is table.insert and the values are written with the = sign not the : that’s it

2 Likes

So like this

local rarityColors = {
	Common = commonColor,
	Uncommon = uncommonColor,
	Rare = rareColor,
	Epic = epicColor,
	Legendary = legendaryColor
	
}
local rarityTextColors = {
	CommonText = TextcommonColor,
	UncommonText = TextuncommonColor,
	RareText = TextrareColor,
	EpicText = TextepicColor,
	LegendaryText = TextlegendaryColor
}
local rarityName = {
	"COMMEN",
	"UNCOMMEN",
	"RARE",
	"EPIC",
	"LEGENDARY"
}

Yes, however you forgot to it for the rarityName table, and the rarityTextColors should use the same key names as rarityColors, so instead of CommonText, use Common and so on. They should all use the same names so it wont error again

I did it but im still getting the same error

local rarityColors = {
	Common = commonColor,
	Uncommon = uncommonColor,
	Rare = rareColor,
	Epic = epicColor,
	Legendary = legendaryColor
	
}
local rarityTextColors = {
	Common = TextcommonColor,
	Uncommen = TextuncommonColor,
	Rare = TextrareColor,
	Epic = TextepicColor,
	Legendary = TextlegendaryColor
}
local rarityName = {
	"Common",
	"Uncommen",
	"Rare",
	"Epic",
	"Legendary"
}

Make sure to also make rarityName a dictionary. If that still doesn’t work, what line is causing the error?

The line that is causing the error is line 63 that’s the line i start changing the color

local function setRarity(rarity)
	local color = rarityColors[rarity]
	local textColor = rarityTextColors[rarity]
--This one	promptGui.Bottom.BackgroundColor3 = color
	promptGui.Top.Divider.BackgroundColor3 = color
	promptGui.Bottom.Rarity.TextColor3 = textColor
	promptGui.Top.WeaponName.TextColor3 = textColor
	promptGui.Bottom.Rarity.Text = rarityName[rarity]
end

That means it’s still getting nil for the color and most likely the text color again, can you print the rarity in the setRarity function and tell me what it says? It’s likely the rarity you’re passing doesn’t match any of the keys in the dictionary

You miss spelled uncommon in the tables, 1 of them is different than the others, could be the reason for it.

1 Like

it printed out LEGENDARY - Client - ShowPrompt:63

That’s why then, your keys are written normally, not in full caps

Change the names of the keys in the dictionary to be full caps, so instead of Common, it’s COMMON and so on

Im now getting this error Unable to assign property Text. string expected, got nil

local function setRarity(rarity)
	local color = rarityColors[rarity]
	local textColor = rarityTextColors[rarity]
	promptGui.Bottom.BackgroundColor3 = color
	promptGui.Top.Divider.BackgroundColor3 = color
	promptGui.Bottom.Rarity.TextColor3 = textColor
	promptGui.Top.WeaponName.TextColor3 = textColor
--On this line promptGui.Bottom.Rarity.Text = rarityName[rarity]
end

Make them caps aswell

This text will be blurred