local ColorA = math.random(1,255)
local ColorB = math.random(1,255)
local ColorC = math.random(1,255)
humanoidRootPart.Color = Color3.fromRGB(ColorA, ColorB, ColorC)
runs before than PlayerAdded and CharacterAdded have fired (so humanoidRootPart is nil when this code runs). You should move this code to the function connected to CharacterAdded.
local humanoidRootPart = nil;
game.Players.PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
humanoidRootPart= char:WaitForChild("HumanoidRootPart")
local ColorA = math.random(1,255)
local ColorB = math.random(1,255)
local ColorC = math.random(1,255)
humanoidRootPart.Color = Color3.fromRGB(ColorA, ColorB, ColorC)
end)
end)
Do you have the output window open? I’m pretty sure your current code gives an error.
I believe I found the issue, your script was trying to change the color of the HumanoidRootPart, when there could possibly be body colors in there that’s overriding the color you are setting. I would recommend using BodyColors
--script must be placed somewhere on server (like ServerScriptService)
local humanoidRootPart = nil;
game:GetService("Players").PlayerAdded:Connect(function(plr)
plr.CharacterAdded:Connect(function(char)
local bodyColors = char:WaitForChild("Body Colors")
humanoidRootPart= char:WaitForChild("HumanoidRootPart")
local ColorA = math.random(1,255)
local ColorB = math.random(1,255)
local ColorC = math.random(1,255)
bodyColors.TorsoColor3 = Color3.fromRGB(ColorA, ColorB, ColorC)
end)
end)
Where is the script located? It should be in ServerScriptService. If it’s in StarterPlayerScripts or StarterCharacterScripts, PlayerAdded will not fire for the first player. Thus, CharacterAdded will only fire when another player spawns because there’s no CharacterAdded connection for the first player because of no PlayerAdded connection for the first player. Also, if it’s in StarterPlayerScripts or StarterCharacterScripts, there will be many scripts doing the same thing which is not good.