Character color customizer not picking up textbox text

Hello. How could I make a character color customizer? This is what I mean:
image

Client:

local selected = nil

local box = script.Parent.TextBox

local player = game.Players.LocalPlayer

for _,v in pairs(script.Parent:GetChildren()) do
	if v:IsA("TextButton") then
		v.MouseButton1Click:Connect(function()
			print(1)
			selected = v.Name
			game.ReplicatedStorage.Character:InvokeServer(selected, box)
		end)	
	end
end

Server:

 function osi(player, selected, box)
	for _,v in pairs(player.Character:GetChildren()) do
		print(2)
		if v:IsA("Part") then
			print(3)
			player.Character[selected].Color = Color3.fromRGB(tonumber(box.Text))
			print(player.Character[selected].Color, selected)
		end
	end
end

game.ReplicatedStorage.Character.OnServerInvoke = osi

It keeps making the color black (0,0,0). I assume it’s not picking up the text. Any ideas?

1 Like

I have another idea for this. Instead making threes in one, you can make 3 TextBoxes which are Red, Green and Blue. After that you can print the color out like this Color3.fromRGB(RedInput, GreenInput, BlueInput).

Doesn’t work. Still prints out 0,0,0.
Client:

        local selected = nil
        local r = script.Parent.R
        local g = script.Parent.G
        local b = script.Parent.B

        local player = game.Players.LocalPlayer

        for _,v in pairs(script.Parent:GetChildren()) do
        	if v:IsA("TextButton") then
        		v.MouseButton1Click:Connect(function()
        			print(1)
        			selected = v.Name
        			game.ReplicatedStorage.Character:InvokeServer(selected, r, g, b)
        		end)	
        	end
        end

Server:

function osi(player, selected, r, g, b)
         for _,v in pairs(player.Character:GetChildren()) do
                if v:IsA("Part") then
                	player.Character[selected].Color = Color3.fromRGB(tonumber(r.Text), tonumber(g.Text), tonumber(b.Text))
                	print(player.Character[selected].Color, selected)
                end
         end
  end

game.ReplicatedStorage.Character.OnServerInvoke = osi

parse r.Text, g.Text and b.Text as you parameters, not the object itself ( r ) or ( g ) or ( b ).

However, if you want to go back to your original method, you could still parse in the arguments as such:

local r,g,b = unpack(script.Parent.TextBox.Text:split(","))

This will split the three terms and put them in a {} table. Then, you can unpack it into individual arguments using the unpack() function, as shown above.

2 Likes

Thanks! But then how could I save those colors? It’s a custom StarterCharacter btw. Obviously I’d have to use tables and datastores, but I’m not sure how.

1 Like

If you want to save those colors in a DataStore, then it’s up to you how.

If you are saving it in a json table along with your other player data, you can do something like let’s say:

local PlayerData = {} -- arbitrary player data that you already have in cache

PlayerData["CharacterColors"] = rgb

rgb being sent to the server as script.Parent.TextBox.Text:split(","), which returns a table

I thought I had to save data on the server. Or do I use a remoteevent?

You could use a RemoteEvent to call the server and keep the data inside of a cache table. Then when the time to saving comes, you can refer to cache for data. Just don’t use calling a remote event to save data. Or do, but be very careful with limits