Hello! I am trying to achieve a working script where it where it will assign colors to the players character (which is a starter character) based on the colors of the players avatar.
It is a ServerScript in ServerScriptService and works as follows:
local Players = game:GetService('Players')
while true do
for _, Player in pairs(Players:GetPlayers()) do
local Character = Player.Character
if Character then
if Character:FindFirstChild('Humanoid') then
if Player:GetAttribute('DoneColours') == nil then
if Player.UserId ~= nil and Player.UserId > 0 then
if Players:GetCharacterAppearanceInfoAsync(Player.UserId).bodyColors ~= nil then
local charinfo = Players:GetCharacterAppearanceInfoAsync(Player.UserId).bodyColors
Player:SetAttribute('DoneColours', true)
for n,v in pairs(charinfo) do
if n == 'leftArmColorId' then
Character['Left Arm'].BrickColor = BrickColor.new(v)
elseif n == 'torsoColorId' then
Character['Torso'].BrickColor = BrickColor.new(v)
elseif n == 'rightArmColorId' then
Character['Right Arm'].BrickColor = BrickColor.new(v)
elseif n == 'headColorId' then
Character['Head'].BrickColor = BrickColor.new(v)
elseif n == 'leftLegColorId' then
Character['Left Leg'].BrickColor = BrickColor.new(v)
elseif n == 'rightLegColorId' then
Character['Right Leg'].BrickColor = BrickColor.new(v)
else
end
end
end
end
end
end
end
end
task.wait(1)
end
However at random times when I join a running server, all players will have gray characters. There are no errors thrown at all, so I do not know what is being done that causes it to stop working. It will work for a while but it seems eventually it will just stop assigning player colors.

Is there anywhere it is possible being hung indefinitely, or isnt written correctly which is causing that issue?
Thanks!