So I have been wanting to set a players team color to a random color when they get a team. So I did some research and found BrickColor.Random()
. I am concerned that this Roblox function does not have a great random algorithm. Because of this I was wondering if I could use something like the Random
object:
local ran = Random.new() local ranNum = ran:NextInteger(1, 5)
except with BrickColors. However I don't know how I would do this. Also I think that the color property of a team must be a BrickColor. If not please tell me because that would make things so much easier. Here is my code in case you were wondering:
local team = Instance.new("Team") local teamColor repeat teamColor = BrickColor.Random() until noTeamColorMatch(teamColor) team.TeamColor = teamColor team.Name = plr.Name.."'s Castle" team.Parent = teams plr.Team = team
Thanks!
Hello Phlegethon5778,
You can do this two ways.
The first would be to use the BrickColor.new()
with a Color3 value.
The second would be to use the BrickColor.palette
function.
Both work, however the first way might be slightly more efficient, and I'll show you why:
function getRandomBrickColor() local color3 = Color3.fromRGB(math.random(0,255),math.random(0,255),math.random(0,255)) local brickColor = BrickColor.new(color3) return brickColor end
This function generates a random color3, and then transfers it into a BrickColor.
The next function makes a table of BrickColors and then picks a random one.
local brickColors = {} function getRandomBrickColor() local brickColor = brickColors[math.random(0,#brickColors)] end for paletteIndex = 0, 127 do table.insert(brickColors,BrickColor.palette(paletteIndex)) end
And there's our two methods of getting a random brick color.
This should be pretty straight forward, but if you've got any questions, feel free to ask!