Attempt to index nil with 'Color'

So I was using a tutorial by polarisprog because I wanted to see what other scripters could accomplish, and I got an error. Please advise.

What’s on the variable “color2”?

That happens when the object does not exist and still passes through its member, children or its property

first check the object like this

local Object = char:FindFirstChild("Capsule")

if Object then
	Object.Color = color2

‘‘local color2 = Color3.fromRGB(math.random(0, 255), math.random(0, 255), math.random(0, 255))’’

it wouldnt work and there were no errors

Try doing char:FindFirstChild('Capsule').Color = Color3.fromRGB(math.random(0, 255), math.random(0, 255), math.random(0, 255)) instead, and see what happens.

Wait nevermind, read the error in the wrong way. Are you sure that for example “Capsule” actually exists inside “char”?

then it just mean the object really dont exist

Screenshot 2022-01-26 at 8.19.18 PM

Screenshot 2022-01-26 at 8.20.20 PM

Try this:

for i,v in pairs(char:GetChildren()) do

it worked for glasses but not for anything else

That means that “Back” and “Capsule” gets deleted on run-time somehow.

How do I fix it? Do I have to do something to stop it getting deleted?

If they aren’t welded to the player, they will fall off and be deleted. To test if this is right, try to anchor them and see if it works then.

I can see that it’s on starter character, so there’s no point on anchoring it.

I recommend using :WaitForChild("OBJECT NAME HERE", 60) so it would also work for users who are lagging. But you can use player.CharacterAdded:Wait() on player added function.

Try this

char:FindFirstChild('Capsule').Color3 = color
char:FindFirstChild('Back').Color3 = color2
char:FindFirstChild('Glasses').Color3 = color2

They’re BasePart instances so they have the “Color” property not the “Color3” property like GuiObject instances do.

1 Like

oop- i thought it was a gui ;-;

its welded to the humanoid root part