Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by
Seyfert 90
7 years ago
Edited 7 years ago

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

Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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
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. Seyfert 90 — 7y
Ad

Answer this question