Issues with setting the transparency of the children in a model

Why isn’t this working its not making the npc visible, this is on the client side and I’ve tried using v:IsA but got the same results.
It prints nothing other than the npc and Done

        print(npc)
        for _, v in pairs(npc:GetDescendants()) do
            --print(v)
            if v.ClassName == "BasePart" then
                print("BasePart")
                if v.Name ~= "CamPartGoal" then
                    if v.Name ~= "HumanoidRootPart" then
                        v.Transparency = 0
                        print("Set")
                    else
                        print("HRP")
                    end
                else
                    print("CamPartGoal")
                end
            elseif v.ClassName == "Decal" then
                print("Decal")
                v.Transparency = 0
            end
        end
        print("Done")
12 Likes

What happens if you uncomment “print(v)”, and where is “npc” defined?

10 Likes

When I uncomment v it prints the instance correctly but nothing else and here is the full script, this is a remote event script

    game.ReplicatedStorage:WaitForChild("showNpc").OnClientEvent:Connect(function(npc)
        print(npc)
        for _, v in pairs(npc:GetDescendants()) do
            print(v)
            if v.ClassName == "BasePart" then
                print("BasePart")
                if v.Name ~= "CamPartGoal" then
                    if v.Name ~= "HumanoidRootPart" then
                        v.Transparency = 0
                        print("Set")
                    else
                        print("HRP")
                    end
                else
                    print("CamPartGoal")
                end
            elseif v.ClassName == "Decal" then
                print("Decal")
                v.Transparency = 0
            end
        end
        print("Done")
    end)

This is what’s firing it

		showNpc:FireClient(player, npc)
7 Likes

image

Apparently when I changed :GetDescendants() to :GetChildren() all it does is print this

4 Likes

Hello, as you can see, the argument “npc” is the humanoid, so try npc.Parent:GetDescendants()

6 Likes

No the npc wouldn’t be the humanoid as you can see here:

local npcLocation: Model = game.ReplicatedStorage:WaitForChild("Rig")

		local npc = npcLocation:Clone()
		npc.Parent = chaseSystemAssets
	
		currentNpc = npc
		
		showNpc:FireClient(player, npc)

I didn’t send the full screenshot on accident here’s the full screenshot:
image

5 Likes

So why in the output when you do print(npc), it prints “Humanoid” and not “Rig”?

5 Likes

I re-edited the message for the full screenshot

7 Likes

Also it only prints animate, which is actually the only descendant of humanoid

6 Likes

Yeah I don’t know why I set all of the body parts transparency to 1 and when I set it to 0 and play the game the body parts are intact so there shouldn’t be an issue of the bodyparts falling out of the void or smthin

I also checked just incase the bodyparts also fell out of the world or something like that as well but when I check explorer everything is intact.

5 Likes

The bodyparts are still intact even when I set it to transparency = 1 and transparency = 0 to clear things up here

6 Likes

animate is not the only descendant of humanoid.
there are values to modify the character

6 Likes

Also try printing in the output npc.parent to see if there is something wrong or not

5 Likes

that should error:
Error: Transparency is not a valid member of…

7 Likes

also, animate is a child of character not humanoid

6 Likes

Yeah then I don’t know what to try

5 Likes

try using pcall

for _, v in npc:GetDescendants() do
   local s, e = pcall(function()
       v.Transparency = 0
   end)
end
5 Likes

Just tried it and it didn’t work for some reason, no errors in console either

5 Likes

Because nothing has a classname set to BasePart. What you want to do is check if the instance inherits from the “BasePart” class. This can be made by doing v:IsA("BasePart") method.


Difference between ClassName and IsA:

ClassName is a property that describes the class of the instance itself. If you have a part, its ClassName is “Part”, not “BasePart”.

IsA() is a function that will check if the instance you are checking is the class you are precising, or if it inherits from this class. In this case, a Part inherits from BasePart, so it returns true. A MeshPart also inherits from BasePart, so it will also return true.

This difference also applies to :FindFirstChild/AncestorOfClass() and :FindFirstChild/AncestorWhichIsA()

Be careful with that.

The code becomes:

print(npc)
for _, v in pairs(npc:GetDescendants()) do
    --print(v)
    if v:IsA("BasePart") then
        print("BasePart") --Does the instance INHERIT from the BasePart class?
        if v.Name ~= "CamPartGoal" then
            if v.Name ~= "HumanoidRootPart" then
                v.Transparency = 0
                print("Set")
            else
                print("HRP")
            end
        else
            print("CamPartGoal")
        end
    elseif v:IsA("Decal") then --Does the instance INHERIT from the Decal class? (NB: since decal is the "end" class, meaning that no other instance inherit from it, you are basically testing if the instance is indeed a decal, it cannot be anything else in this case.
        print("Decal")
        v.Transparency = 0
    end
end
print("Done")

shortened to

for _, v in pairs(npc:GetDescendants()) do
    if v:IsA("BasePart") or v:IsA("Decal") then --class check (taking inheritance into account)
        if v.Name ~= "CamPartGoal" and v.Name ~= "HumanoidRootPart" then --name check
            v.Transparency = 0
        end
    end
end

Lmk if it worked by putting this post as the solution!

3 Likes

I don’t know what happened it didn’t work and I got no errors in console.

2 Likes