Hello...I'm trying to select a random color value from a table but it returns with Workspace.Scripts.randomNPC:14: invalid argument #2 to 'random' (interval is empty)
Here is a snippet of my script:
local Colors = { Color1 = Color3.fromRGB(255,229,180), Color2 = Color3.fromRGB(222,184,135), Color3 = Color3.fromRGB(139,69,19) } local randomColor = Colors[math.random(1,#Colors)] for _,limb in pairs(npc:GetChildren()) do if limb:IsA("BasePart") then limb.Color = randomColor end end
help?
Try making the index for each value of Colors
an integer 1, 2, or 3 instead of Color1, etc.
The reason for the error is that #Colors
equals 0, and (1,0) is an empty interval.
(You have a dictionary instead of an array)