Colors/colours table won't work

  1. What do you want to achieve? Keep it simple and clear!

I have a table of colors/colours and I want math.random to pick a random color from the table.

  1. What is the issue? Include screenshots / videos if possible!

The issue is that I keep getting this error:

Chat.ClientChatModules.MessageCreatorModules.Util:99: invalid argument #3 (Color3 expected, got number)

Local script inside StarterGui - Code

local StarterGui = game:GetService("StarterGui")
local player = game.Players.LocalPlayer

local colors = {
	Color3.new(0.13135, 0.99968, 0.023621),
	Color3.new(0.000106813, 0.00175479, 0.998215),
	Color3.new(0.986252, 0.00712596, 0.0274357)
}

local color = math.random(1, #colors)

local function joinedMessage()
	repeat wait() until player.Character
	StarterGui:SetCore("ChatMakeSystemMessage", {
		Text = player.Name.." has joined the game!";
		Color = color;
		Font = Enum.Font.ArialBold;
		Size = 20;
	})
end

game.ReplicatedStorage.Joined.OnClientEvent:Connect(function()
	joinedMessage()
	print(player.Name.." has joined the game")
end)

Can anybody help?

This is the wrong bit, this gets a random number between 1 and the number of colours
What you want instead is

local color = colors[math.random(1, #colors)]

I don’t know if you want a different colour each time, if so then you’d need to move this into the joinedMessage() function, at the moment this random colour is just picked once and will then be used for every player who joins.

Hope that helps,