Still have questions? Join our Discord server and get real time help.
0

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

Edited 1 year ago
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;
};

};

0
I think we need more of the code roy6576 234 — 1y

0

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.

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 anthonypjo 5 — 1y
0
first of all what is deptlist[i]? DeceptiveCaster 3043 — 1y
0
more specifically, where is i defined? DeceptiveCaster 3043 — 1y
0
in a module script anthonypjo 5 — 1y
0
ok, so why is it defined in a separate script? DeceptiveCaster 3043 — 1y
0
because other scripts need to access those values anthonypjo 5 — 1y
0
so then what is deptlist? DeceptiveCaster 3043 — 1y
0
i edited the question and included the module script which is deptlist anthonypjo 5 — 1y
0

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