Hi,
I’m making an among us game in roblox and I am trying to make a script that gives you a random color that is different for each player however no matter what I do it will always put multiple players with the same color.
Here is my code:
game.Players.PlayerAdded:Connect(function(player)
player.CharacterAdded:Connect(function(char)
if not player:FindFirstChild(“Color”) then
local colors = {
BrickColor.new(“Really red”),
BrickColor.new(“Really blue”),
BrickColor.new(“Camo”),
BrickColor.new(“Hot pink”),
BrickColor.new(“Bright orange”),
BrickColor.new(“New Yeller”),
BrickColor.new(“Really black”),
BrickColor.new(“Institutional white”),
BrickColor.new(“Royal purple”),
BrickColor.new(“Burnt Sienna”),
BrickColor.new(“Cyan”),
BrickColor.new(“Lime green”),
BrickColor.new(“Smoky grey”),
}
local randomColor
local lastColor1
local lastColor2
local lastColor3
local lastColor4
local lastColor5
local lastColor6
local lastColor7
local lastColor8
local lastColor9
local lastColor10
local lastColor11
local lastColor12
local lastColor13
local lastColor14
local lastColor15
local lastColor16
for i = 1,16 do
if not randomColor or not randomColor == i then
randomColor = colors[math.random(1,#colors)]
end
end
for i,v in pairs(char:GetDescendants()) do
if v:IsA("BasePart") or v:IsA("MeshPart") or v:IsA("UnionOperation") then
if not v:FindFirstChild("NotColorable") then
v.BrickColor = randomColor
local color = Instance.new("BrickColorValue",player)
color.Value = randomColor
color.Name = "Color"
local env = getfenv()
for i = 1,16 do
if i == nil then
env["lastColor"..i] = randomColor
break
end
end
end
end
end
end
end)
end)