Why isn't this working?

I tried this with normal color brickcolor and more why doesn’t this work?
Screenshot 2024-11-16 192252

2 Likes

Is thing‘s text a color value? (ie RGB)
If it’s not, it won’t change the color, because there’s no color to change.
And can you elaborate on what specifically isn’t working?

1 Like

it’s a thing where you type into a textbox (a rgb color code) and when you enter it the ball becomes the color you put in so if you put in 0, 0, 0 enter it then it becomes black

1 Like

So the problem is that typing in a color value doesn’t change the color?
If so refer to @iforgor123456789016’s posts below.

You have to use Color for the part’s color and Color3.new for setting the color

It should look like this

game.Workspace.Theball.Color = Color3.new(thing)
  1. thing may not be loaded
  2. the current text won’t be applied to the color
  3. you’re using brickcolor

i tried it and it just keeps turning to black

thing will always be black because it’s not being updated with the textbox (you got the textbox’s text once)

move thing into the function

1 Like

that will not work because the text is still going to be a string and not a number. but you can use tonumber and string.sub

2 Likes

i tried it and it’s still black

1 Like

sorry but can you put that into a string of code? i’m not good with that

1 Like

@RemainingDino Try this!

local debounce = false
local Thing = workspace.test1.SurfaceGui.TextBox.Text

script.Parent.MouseClick:Connect(function()
	if debounce == false then
		debounce = true
		workspace.TheBall.Color = Color3.new(tonumber(Thing))
		workspace.TheNewBall.Color = Color3.new(tonumber(Thing))
	end
	task.wait(10)
	debounce = false
end)

Here, I am using tonumber, which is a function that converts a string into a number. For example, if you type into the TextBox 255, 255, 255 (which is the color black in Roblox) then it will change the color of your parts to black. It will work with any color.

Read more about it here: Lua Globals | Documentation - Roblox Creator Hub

Hope this helps and let me know if you have any questions! :slight_smile:

2 Likes

Heres an updated version

local splitstring = string.split(thing, ", ")

local r = tonumber(splitstring[1])
local g = tonumber(splitstring[2])
local b = tonumber(splitstring[3])

game.Workspace.Theball.Color = Color3.fromRGB(r, g, b)
1 Like

im not sure this will work because typing something that isn’t a number into this will make tonumber return nil

1 Like

thing still will be black because its not being updated
and the commas aren’t being separated if it’s (r, g, b) input

1 Like

let me know if this works:

local debounce = false
local thing = game.Workspace.test1.SurfaceGui.TextBox.Text

script.Parent.MouseClick:Connect(function()
	if debounce == false then
		debounce = true
		local r, g, b = string.match(thing, "%s*(%d+%.?%d+)%s*,%s*(%d+%.?%d+)%s*,%s*(%d+%.?%d+)%s*")
		if not r or not g or not b then
			print("Didn't format the RGB correctly")
			return
		end
		game.Workspace.Theball.Color = Color3.fromRGB(tonumber(r), tonumber(g), tonumber(b))
		game.Workspace.Thenewball.Color = Color3.fromRGB(tonumber(r), tonumber(g), tonumber(b))
	end
	task.wait(10)
	debounce = false
end)
2 Likes

‘thing’ will still be black x2

1 Like

it works perfectly fine on my end, maybe change the text property in studio for it to work

1 Like

it’s black for me still how do i change the text property do you mean the one on thing?

1 Like