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")
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)
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.
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!