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

Why is this color3 so badly made? why does it print so much random stuff and not work?

ok so, i have some BADLY written code that i need some coding guru to take a look at!! I just don't understand why my gui textbuttons color keeps showing up black... Like even though i like black stuff, I don't understand why its not some other color, here is my pathetic code..

(Dont worry about the variables and all)

for _, v in pairs(game.ReplicatedStorage.Shop_Items:WaitForChild(typeC):GetChildren()) do
		local new = game.ReplicatedStorage.Shop_Items.Default_Button:Clone()
		new.Parent = Main.Purchase_Chest.Main
		new.Name = v.Name
		new.Text = v.Name
		local obj = game.ReplicatedStorage.Shop_Items:WaitForChild(typeC):FindFirstChild(v.Name)
		print(obj.Color)
		new.BackgroundColor3 = Color3.new(obj.Color)
	end

it all works except the background color doesnt change to the other color

example:

local color = workspace.Part

gui.BackgroundColor3 = Color3.new(color.Color)

In the example above i try changing the background color to whatever the parts color is but it will forever show up black, I will never understand it, help please. thx

1 answer

It shows up as black because it's an invalid color.

Solution

Your code

local color = workspace.Part

gui.BackgroundColor3 = Color3.new(color.Color) --color.Color is already a color3 value

What it should be

local color = workspace.Part

gui.BackgroundColor3 = color.Color

Color3.fromRGB()

If you further set colors of things, I suggest you use Color3.fromRGB() because it makes sense. Color3.new() uses values from 0 to 1 where Color3.fromRGB() uses values from 0 to 255.

gui.BackgroundColor3 = Color3.new(100/255, 100/255, 100/255)
gui.BackgroundColor3 = Color3.fromRGB(100, 100, 100)

7 comments

0

tried thta ^_^

0

i noticed it prints colors like 0 1 0 1 0 0 1

0

It's working fine for me, I just tested it in studio?

0

remember i have to set it to another color3, i cant use numbers...

0

I don't understand. Are you setting a GUI's color to match a part's color or is it more than that? What is the "obj" variable's class?

0

obj is a particle emitter, I am trying to set a gui color to a particles color

0

Particle emitters are a color sequence. Use ColorSequence.new() to do it. https://developer.roblox.com/api-reference/datatype/ColorSequence

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