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

Why does this make the background color of the textbutton black? [SOLVED]

b = Instance.new("TextButton")
		b.Name = deptlist[i].Name
		b.BorderSizePixel = 0
		b.BackgroundTransparency = 1
		print(BrickColor.new(deptlist[i].Color).Color)
		b.BackgroundColor3 = Color3.new(BrickColor.new(deptlist[i].Color).Color)
		b.Text = string.upper(deptlist[i].Name)
		b.TextSize = 50
		b.TextScaled = true
		b.TextXAlignment = "Left"
		b.TextColor3 = Color3.new(255,255,255)
		b.Parent = teams.Selection

deptlist[i].Color is a brickcolor

here is the module script

return {
	
	{ ["Name"] 			= "Indian Citizen";
	  ["Tag"]			= "Citizen";
	  ["Color"]			= "Deep orange";
	  ["GroupId"]		= 919408;
	};

};

1 comment

0

I think we need more of the code

2 answers

Color3.new() can only take a number in each value (x,y,z) from 0 to 1. You must be giving it higher than that range, which forces the color to be black. In order to make the desired color appear, use Color3.fromRGB():

b.BackgroundColor3 = Color3.fromRGB(BrickColor.new(deptlist[i].Color).Color) -- This should fix the problem

Color3.fromRGB() works because its range is from 0 to 255, making it easier to create colors.

8 comments

0

Well it still give me black unfortunately. I have been experimenting with print() If you do like print(BrickColor.new("Earth green").Color) it will print(0.152941, 0.27451, 0.176471) If you add color3.new or color3.fromRGB to this it will give 0,0,0

0

first of all what is deptlist[i]?

0

more specifically, where is i defined?

0

in a module script

0

ok, so why is it defined in a separate script?

0

because other scripts need to access those values

0

so then what is deptlist?

0

i edited the question and included the module script which is deptlist

So I found the answer by experimenting and I figured out (after way too long) that the

color = BrickColor.new(deptlist[i].Color).Color

gives out a color3

So when you change the background color, you do not need to add color3.new(), just color like this

  b.BackgroundColor3 = BrickColor.new(deptlist[i].Color).Color

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