Chat RGB Command Help

I’m currently attempting to make an RGB command in chat that sets the text color to the second, third, and fourth argument in the chat.

Command example:
:setcolor 255, 255, 255

I made this command successfully, but if I put in an RGB color code, it sets it to a whole different color.

My code:

game.Players.PlayerAdded:Connect(function(Player)
	Player.Chatted:Connect(function(Message)
		local SplitMessage = Message:split(" ")
		if SplitMessage[1] == ":setcolor" then
			local FirstArgument = SplitMessage[2]
			local SecondArgument = SplitMessage[3]
			local ThirdArgument = SplitMessage[4]
			Player.Character.Head:FindFirstChild("Rank").Frame.Player.TextColor3 = Color3.fromRGB(tonumber(FirstArgument), tonumber(SecondArgument), tonumber(ThirdArgument))
			Player.Character.Head:FindFirstChild("Rank").Frame.Rank.TextColor3 = Color3.fromRGB(tonumber(FirstArgument), tonumber(SecondArgument), tonumber(ThirdArgument))
		end
	end)
end)

Can you please explain further? You’re saying that the color you’re getting is completly wrong?

That may be happening because you’re putting a comma in the command, which would break the RGB color. It would be basically doing this:

Color3.fromRGB(255,,255,,255)

To fix that try not using comma in your command: :setcolor 255 255 255

1 Like

Yep, that worked. I completely forgot that it would double the commas! Thanks for the help :smile:

Not exactly, it’s not creating extra arguments. With the command set up, :setcolor 255, 255, 255 would return the three argument as strings. The issue lies with the tonumber methods - since each one would be receiving a string as num, it wouldn’t be considered a number due to the extra comma, thus when given to tonumber it will return nil.

local Number = tonumber("255,")
print(Number) -- nil

In the case of the OP’s code, this is what was happening when he chatted “:setcolor 255, 255, 255”:

Frame.Player.TextColor3 = Color3.fromRGB(nil, nil, nil)
Frame.Rank.TextColor3 = Color3.fromRGB(nil, nil, nil)

To prevent such a case from happening in the future, he could use gsub to remove the commas.

local Message = ":setcolor 255, 255, 255"
local SplitMessage = Message:gsub(",", ""):split(" ")
print(table.concat(SplitMessage, ">")) -- :setcolor>255>255>255

I hope this helped. :slight_smile:

1 Like