Invalid argument #2 to ‘random’ (interval is empty) error

Hey there so I keep getting this error

  09:36:35.008 - ServerScriptService.PlayerStats:28: invalid argument #2 to 'random' (interval is empty)

And I don’t know how to fix it. my FULL script is

---Lighting Settings----

local Lighting = game:GetService("Lighting")
Lighting.ClockTime = 22
Lighting.FogColor = Color3.fromRGB(0,0,0)
Lighting.FogEnd = 200
Lighting.Brightness = 1


local ColorsTable = {}
Color3.fromRGB(255, 0, 0) ---Red
Color3.fromRGB(255, 85, 0)--Orange
Color3.fromRGB(255, 255, 255) ---White
Color3.fromRGB(209, 255, 0)---Yellow
Color3.fromRGB(0, 0, 127)---Blue
Color3.fromRGB(0, 0, 0)---Black
Color3.fromRGB(255, 20, 232)---Pink
Color3.fromRGB(98, 0, 88)---Purple
Color3.fromRGB(3, 74, 3)---Green
Color3.fromRGB(85, 255, 0) ---Lime 



game.Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		
		local Parts = char:GetChildren()
		local RandomColor = ColorsTable [math.random(1,#ColorsTable)]
		for i = 1, #Parts do
			if Parts[i].ClassName == "MeshPart" or Parts[i].ClassName == "Part" then
				Parts[i].Color = RandomColor
			end
		end
		-----------------------------
		local NameTagClone = script.NameTag:Clone()
		NameTagClone.Parent = char:FindFirstChild("Head")
		NameTagClone.Label.Text = plr.Name
	end)
end)

error line is

local RandomColor = ColorsTable [math.random(1,#ColorsTable)]

Please help!

You didn’t actually put the colors in the table,

local ColorsTable = {
    Color3.fromRGB(255, 0, 0) ,---Red
    Color3.fromRGB(255, 85, 0),--Orange
    Color3.fromRGB(255, 255, 255), ---White
    Color3.fromRGB(209, 255, 0),---Yellow
    Color3.fromRGB(0, 0, 127),---Blue
    Color3.fromRGB(0, 0, 0),---Black
    Color3.fromRGB(255, 20, 232),---Pink
    Color3.fromRGB(98, 0, 88),---Purple
    Color3.fromRGB(3, 74, 3),---Green
    Color3.fromRGB(85, 255, 0), ---Lime 
}
2 Likes

You never added the colors to the table. I would do it like this:

local ColorsTable = {
Color3.fromRGB(255, 0, 0), ---Red
Color3.fromRGB(255, 85, 0),--Orange
Color3.fromRGB(255, 255, 255), ---White
Color3.fromRGB(209, 255, 0),---Yellow
Color3.fromRGB(0, 0, 127),---Blue
Color3.fromRGB(0, 0, 0),---Black
Color3.fromRGB(255, 20, 232),---Pink
Color3.fromRGB(98, 0, 88),---Purple
Color3.fromRGB(3, 74, 3),---Green
Color3.fromRGB(85, 255, 0) ---Lime 
}
2 Likes

Okay I will do that and see if that works.

1 Like

Thank you! it worked and thank you @SyntaxDefinition too! :smiley:

1 Like

Don’t worry, feel free to message me if you have any other problems.