I’m working on a small project and I thought of adding some color customization. How can I use variables as RGB values, and/or how can i get a variable from a textbox input?
Here’s the code:
local x = bckg.Frame.x.TextBox.Text
local y = bckg.Frame.y.TextBox.Text
local z = bckg.Frame.z.TextBox.Text
bckg.BackgroundColor3 = Color3.fromRGB(x, y, z)
You either need to set the color when the text of x, y, or z changes with TextBox:GetPropertyChangedSignal'Text' or make a button that you click that updates the colors
You can’t do that. When referencing the TextBox.Text part, you basically make a variable that contains whatever TextBox.Text was at that time. If the text changes, it won’t work.
Try this:
local x = bckg.Frame.x.TextBox
local y = bckg.Frame.y.TextBox
local z = bckg.Frame.z.TextBox
bckg.BackgroundColor3 = Color3.fromRGB(tonumber(x.Text), tonumber(y.Text), tonumber(z.Text))
local x = bckg.Frame.x.TextBox.TextColor3.R
local y = bckg.Frame.y.TextBox.TextColor3.G
local z = bckg.Frame.z.TextBox.TextColor3.B
bckg.BackgroundColor3 = Color3.fromRGB(x, y, z)
Now, what you did is get the string of the TextBox and you didn’t convert it into a number. To convert that variable, you can just do “local x,y,z = tonumber(bckg.Frame.x.TextBox.Text), tonumber(bckg.Frame.y.TextBox.Text), tonumber(bckg.Frame.z.TextBox.Text)”.
I hope that helped, just remember that the parameters of Color3 are numbers and not strings!!!
local colors = {
x = bckg.Frame.x,
y = bckg.Frame.y,
z = bckg.Frame.z
}
function changeColor()
local x, y, z = colors[1].Text, colors[2].Text, colors[3].Text
bckg.BackgroundColor3 = Color3.fromRGB(
tonumber(x) or 255,
tonumber(y) or 255,
tonumber(z) or 255
)
end
for _, textBox in pairs(colors) do
textBox:GetPropertyChangedSignal('Text'):Connect(changeColor)
end