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

How to set a Color3 from a dictionary using a for loop?

I have the dictionary:

local Jobs = {}

Jobs.AvailableJobs = {}

Jobs.AvailableJobs["PizzaChef"] = {
	Name = "Pizza Chef", 
	Photo = 1935181781, 
	ReqLvl = 1,
	TextC = Color3.new(225, 153, 89)
}

Jobs.AvailableJobs["StoreClerk"] = {
	Name = "Store Clerk", 
	Photo = 1935181761, 
	ReqLvl = 1,
	TextC = Color3.new(59, 154, 0)
}

Jobs.AvailableJobs["PoliceOfficer"] = {
	Name = "Law Enforcement", 
	Photo = 1935181751, 
	ReqLvl = 2,
	TextC = Color3.new(63, 148, 179)
}

Jobs.AvailableJobs["Medic"] = {
	Name = "Doctor", 
	Photo = 1935181725, 
	ReqLvl = 3,
	TextC = Color3.new(193, 35, 35)
}

return Jobs

But every time I try to set the text's color using a for loop, it only applies StoreClerk's color as yellow, when it's supposed to be green, and the others just stay white.

Here is the for loop:

	for id, v in pairs(Jobs.AvailableJobs) do

		local JobName = Instance.new("TextButton", JobBox)
		JobName.BackgroundTransparency = 1
		JobName.ZIndex = 2
		JobName.Position = UDim2.new(0.175,0,0.748,0)
		JobName.Size = UDim2.new(0,130,0,40)
		JobName.Text = Jobs.AvailableJobs[id].Name
		JobName.TextColor3 = Jobs.AvailableJobs[id].TextC
		JobName.TextStrokeTransparency = 0
		JobName.TextStrokeColor3 = Color3.new(0,0,0)
		JobName.TextWrapped = true
		JobName.TextSize = 15

	end

1 answer

✓ Accepted answer

Color3.new takes the R,G and B colours as a value between 1 and 0, rather than 0 to 255. To fix this, use Color3.fromRGB instead in the dictionary:

TextC = Color3.fromRGB(225, 153, 89)

1 comment

0

Thank you, this seems to do it!

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