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

How do I convert a StringValue to a Color3Value?

In my game, I have a TextBox where you can enter an RGB value, and then send it to the server where it'll use it to change a value. However, the server keeps outputting the error, "Expected Color3, got string".

On the client side:


script.Parent.MouseButton1Click:Connect(function()
	local ReplicatedStorage = game:GetService("ReplicatedStorage")
	local SubmitTeamChanges = ReplicatedStorage:WaitForChild("SubmitTeamChanges")
	Team1PrimaryColor = script.Parent.Parent.Team1PrimaryColor.Text
	SubmitTeamChanges:FireServer(Team1PrimaryColor)
end)

On the server side:


local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SubmitTeamChangesEvent = Instance.new("RemoteEvent", ReplicatedStorage)
SubmitTeamChangesEvent.Name = "SubmitTeamChanges"
local function onSubmitTeamChanges(player, Team1PrimaryColor) 
	workspace.Teams.Team1.PrimaryColor.Value = Color3.fromRGB(Team1PrimaryColor)
end
SubmitTeamChangesEvent.OnServerEvent:Connect(onSubmitTeamChanges)

The "PrimaryColor" Instance in the workspace is a Color3Value

Any solutions? I can't figure out how to send Color3Values from the client.

1 comment

0

well, you could have text boxes each suppose to take a diffrent value; for ex: text box 1 takes the value for red, text box 2 takes the value for green, and etc, then use them as arguments to color3.new()

1 answer

✓ Accepted answer

The best way I could think of is make them insert three strings (r, g, and b)

Then, you could do something like

local rvalue=tonumber(r)
local gvalue=tonumber(g)
local bvalue=tonumber(b)

local rgb=Color3.new(rvalue,bvalue,gvalue)

Explanation:

This finds the length from comma to comma, then gets whatever number is in the middle.

Or something like:

local text= "73,37,40"

local length1=string.find(text,",")
length1=length1-1

local num1=string.sub(text,1,length1)



local length2=string.find(text,",",length1+2)
length2=length2-1


local num2=string.sub(text,length1+2,length2)



local num3=string.sub(text,length2+2,string.len(text))



local combined= num1..num2..num3

local color=Color3.new(num1,num2,num3)
print(combined)

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