v:IsA("Accessory") resulting in "attempt to call a nil value"

The title says it all. I didn’t wanna ask help but… I’m so confused. Like I have no clue of why it isn’t working and what should I do. This is the line of code:

local rp = game:GetService("ReplicatedStorage")
local hairs = rp:GetChildren()
for i,v in pairs(hairs) do
	if v:IsA("Accessory") then --this is line 142, the one from the error
		v.Handle.BrickColor = BrickColor.new("Black")
	end
end

image

I should also say that I used the same exact line in another piece of code (I did copy and paste), and it works just perfectly. So… what’s wrong here?

apparently Accessory is not a valid IsA, so just use v.ClassName == “Accessory” instead

3 Likes

That’s so weird tho… cause when I type “Accessory” in IsA this pops up:
Annotazione 2020-08-22 135534

I know, it’s probably some sort of bug. I’ve had this issue too and resolved to using ClassName

I don’t see any error.
Follow these -

  • Make sure you have put the item inside the ReplicatedStorage
  • Make a folder inside of ReplicatedStorage and put the hair inside the folder.
local rp = game:GetService("ReplicatedStorage")
local hairs = rp.Folder:GetChildren() -- change this to the name of your folder
for i,v in pairs(hairs) do
	if v:IsA("Accessory") then --this is line 142, the one from the error
		v.Handle.BrickColor = BrickColor.new("Black")
	end
end
  • Try using v.ClassName == “Accessory”

Alright, it’s a bug for real I guess. Anyways, your solution worked. Thank you my guy. I hope Roblox fixes that before people break their scripts for a dumb bug.

As you can see, I did put them into ReplicatedStorage. Using a folder results in the same error. As I said in my original post, it works fine in other lines of code. That’s what is concerning me.
Cattura

1 Like

You could try if v:IsA("Accoutrement") then as well. Accoutrement includes Accessory and the legacy Hat class.