Just remove the hashtag, it’s not needed. Secondly, you have made a dictionary; you need an array to use the # operator to find the number of elements on the table.
local bucnhOfColor = {
"Pastel brown",
"Neon orange",
"Nougat",
"Reddish brown",
}
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAppearanceLoaded:Connect(function(char)
wait(0.5)
local val = plr:WaitForChild("stats"):WaitForChild("SkinColor").Value
if val >= 1 then
wait(1)
if val <= #bucnhOfColor then
char["Body Colors"].HeadColor = BrickColor.new(bucnhOfColor[val])
char["Body Colors"].LeftArmColor = BrickColor.new(bucnhOfColor[val])
char["Body Colors"].RightArmColor = BrickColor.new(bucnhOfColor[val])
char["Body Colors"].LeftLegColor = BrickColor.new(bucnhOfColor[val])
char["Body Colors"].RightLegColor = BrickColor.new(bucnhOfColor[val])
char["Body Colors"].TorsoColor = BrickColor.new(bucnhOfColor[val])
end
end
end)
end)
There’s two reasons as to why this didn’t work. One being, the elements in the table. The other being, char["Body Colors"].HeadColor & others accept a BrickColor value and not a Color3 value. To fix this, you could do BrickColor.new(StringColor).Color which returns a Color3 value of BrickColor StringColor.
-- ServerScript
local bunchOfColors = {
BrickColor.new("Pastel brown"),
BrickColor.new("Neon orange"),
BrickColor.new("Nougat"),
BrickColor.new("Reddish brown"),
}
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAppearanceLoaded:Connect(function(char)
local val = plr:WaitForChild("stats"):WaitForChild("SkinColor").Value
-- If val lower than 0, val = 1 (first value in table)
if val <= 0 then
val = 1
-- If val greater than the number of vales in table, val = #table (last value in table)
elseif val > #bunchOfColors then
val = #bunchOfColors
end
char["Body Colors"].HeadColor = bunchOfColors[val]
char["Body Colors"].LeftArmColor = bunchOfColors[val]
char["Body Colors"].RightArmColor = bunchOfColors[val]
char["Body Colors"].LeftLegColor = bunchOfColors[val]
char["Body Colors"].RightLegColor = bunchOfColors[val]
char["Body Colors"].TorsoColor = bunchOfColors[val]
end)
end)
I take zero credit. I just ironed out some bugs in everyone’s code.
Working
local bunchOfColors = {
BrickColor.new("Pastel brown"),
BrickColor.new("Neon orange"),
BrickColor.new("Nougat"),
BrickColor.new("Reddish brown"),
BrickColor.new("Really blue"),
}
game.Players.PlayerAdded:connect(function(plr)
plr.CharacterAppearanceLoaded:Connect(function(char)
local plrname = plr.Name
local actualval = Instance.new("IntValue")
actualval.Parent = workspace:WaitForChild(plrname)
actualval.Value = 0
local val = actualval.Value
-- If val lower than 0, val = 1 (first value in table)
if val <= 0 then
val = 1
-- If val greater than the number of vales in table, val = #table (last value in table)
elseif val > #bunchOfColors then
val = #bunchOfColors
end
char["Body Colors"].HeadColor = bunchOfColors[val]
char["Body Colors"].LeftArmColor = bunchOfColors[val]
char["Body Colors"].RightArmColor = bunchOfColors[val]
char["Body Colors"].LeftLegColor = bunchOfColors[val]
char["Body Colors"].RightLegColor = bunchOfColors[val]
char["Body Colors"].TorsoColor = bunchOfColors[val]
end)
end)
Disclaimer & Info
This will run only once. To modify it to run and always check, turn it into a loop.
This is susceptible to exploiters. It determines the color of the player based on a simple IntValue, which an exploiter could easily change as it’s stored on the client, not the server. You can fix this by creating the IntValue in ServerStorage.
The fatal flaw everyone’s code was the val variable was looking for a .Value, which didn’t exist.