Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is "Decal is not a valid member of Part" occuring?

Okay please take note

--------------------Model

---------Brick

--------------Decal

---------Brick

--------------Decal

---------Brick

--------------Decal

---------Brick

-------------Decal

That is what my model looks like, I have this code



local orderboard = game.Workspace.ModelCollection:GetChildren()
local ID = game.Workspace.ReferenceDecal.Texture

for i, v in pairs(orderboard) do  	
      if v.Decal.Texture == ID then 
		---extra stuff goes here
      end
end

I keep getting the error

Decal is not a valid member of Part

Why is this? Shouldn't the for loop be able to iterate things inside of the brick?

1 answer

✓ Accepted answer

It seems like one of the Parts in ModelCollection doesn't have a Decal.

Check if the descendant has a decal, before attempting to index it.

local orderboard = workspace.ModelCollection:GetChildren()
local ID = workspace.ReferenceDecal.Texture

for i, v in pairs(orderboard) do
	local Decal = v:FindFirstChild("Decal")
	if Decal then --Check if it exists
		if Decal.Texture == ID then 
			---extra stuff goes here
		end
	end
end

1 comment

0

That was it, thank you so much you are very good. I never thought about putting checks to see if these exist in the for loops or if statemetns. Thank you truly, I had some bricks in the model that did not have any Decals and I did not notice that.

This discussion is preserved as it was. New answers, comments, and votes are closed.