How do I change a TextButtons background color from a value

Hello, So I am working on a game lately and I have run into a problem I’m trying to make it when the player clicks a button a list of colors show that I have put in a folder.
I got that to work all that happens is that when I click the button all it shows is a list of black buttons.
RobloxScreenShot20230112_174145333
Here is my script.

local ColorFrame = script:WaitForChild(“Color”)
local ColorFolder = game.ReplicatedStorage:WaitForChild(“Colors”)

local StorageFrame = script.Parent.Parent.Parent.Parent.MapMaterials.MaterialList

script.Parent.MouseButton1Click:Connect(function()
StorageFrame.Parent.Visible = true
for i, Children in pairs(ColorFolder:GetChildren()) do
local Clone = ColorFrame:Clone()
Clone.Parent = StorageFrame
Clone.Name = Children.Name

	local Vec3 = Children.Value
	--local Color = Color3.fromRGB(Vec3.X, Vec3.Y, Vec3.Z)
	
	Clone.BackgroundColor3 = Color3.fromRGB(Vec3)
	
	Clone.MouseButton1Click:Connect(function()
		
		wait(0.25)
		
		for i, DeleteChildren in pairs(StorageFrame:GetChildren()) do
			if DeleteChildren:IsA("TextButton") then
				DeleteChildren:Destroy()
			end
		end
		
		wait(0.05)
		
		for i, Materials in pairs(workspace.MapGround:GetChildren()) do
			if Materials.Name == "Ground" then
				Materials.Color = Clone.BackgroundColor3
			end
		end
		
		StorageFrame.Parent.Visible = false
		script.Parent.Parent:WaitForChild("MapMaterialFrame").Image = Clone.Image
	end)
end

end)

If you need anymore information just ask and I am happy to give it.

I… really… disapprove of this:

There’s a dedicated value object for this, it’s Color3Value. You do not need to do Vec3.X or something, all you have to do is use the .Value of the Color3Value:

local Col3 = Children.Value -- Color3Value.Value

Clone.BackgroundColor3 = Col3 -- That's it.

Plus, using Attributes (personally) is better than using a bunch of values (less clutter in the Explorer).

Finally, please wrap your code in [```]'s to make your code readable.
Example:
```
from this
```

to this

It works thanks and next tine I will use

Thanks again.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.