Descendant Disaster

Hello, today I was messing around in studio looking for new things to learn and I found a way to grab a characters appearance and tried to make a simple script.

local appearanceModel = game.Players:GetCharacterAppearanceAsync(120338859) --my character
local parts = appearanceModel:GetChildren() --descendents


for i, parts in pairs(parts) do
	if parts.ClassName == "Part" then --checks if the object is a part
	parts.Anchored = true --anchores the part
	
	end
end
appearanceModel.Parent = game.Workspace --sets the models parent to the workspace

I probably made a small mistake and any help would be appreciated. Thanks!

Hmm, I think they’re accessories instead of parts.
Not everything you see in workspace are “parts”, some of them are wedge or meshpart.
Just check their ClassName, they are different.

1 Like

How would I filter out everything I don’t want?

I think’s the script’s confused. parts is a variable for appearanceModel:GetChildren() but then you’re doing for i, parts in pairs(parts). Try changing the for loop to this:

for i, part in pairs(parts) do
-- code here
end

It’ll still work, it’s just a bit confusing.

2 Likes

You can use ~=, that is the meaning of not equal.

1 Like

I tried this but got an error saying [Anchored is not a valid member of NumberValue]

I tried this but I got an error that stated [Anchored is not a valid member of NumberValue]

Then you forgot to black list NumberValue.

Never check the ClassNames, here is the Instance:IsA(ClassName) function that return a boolean if the Instance is from this class or not. This works with inheritance (i.e.: Part:IsA(“BasePart”) --returns true). You can use google to check out how to use it.

A little example:

local TargetedInstance = YourInstance
local TargetedClass = YourTargetedClass
print(TargetedInstance:IsA(TargetedClass)) --If you chose as Instance a Part and as class the BasePart class, then this returns true. Check out the Devhub for more informations!

So, i would change your Code to distingue BaseParts from Accessories. Dont ask for a whole code, this is against the rules.

I think this is cause appearanceModel doesn’t return the data type table. On another note, it may be that ClassName is deprecated as far as I can remember, correct me if I am wrong but you should replace the if statement with if parts:IsA("BasePart") then

Now looking at your code I think it is because your appearanceModel data can’t be represented with a nil parent. You should also try setting its parent to the workspace immediately after defining the variable.

Instance.ClassName is not deprecated, you simply not use it.

Yes, but @dorious need to distinguish if the part is a normal Part (BasePart) or a accessory (Accessory). He has the code, he only need to change it a bit. He can print the ClassNames (not deprecated) using the print function

print(i, parts.ClassName)

And i would use ipairs instead of pairs. Why? Because Instance:GetChildren() return a array, not a dictionarry. More information are on the DevHub.

1 Like

I am currently trying to learn ipairs and I have tried @Diamond_Plus1 method but no parts loaded
ro

Well I don’t see any parts there, what exactly does that asynchronous method return anyways?

1 Like

Show us what you wrote, pls 30 Charrs

local appearanceModel = game.Players:GetCharacterAppearanceAsync(120338859) --my character

local parts = appearanceModel:GetChildren() --descendents

appearanceModel.Parent = game.Workspace --sets the models parent to the workspace

for i, part in ipairs(parts) do

if part:IsA(“BasePart”) then

part.Anchored = true

end

end

Then debug it. You can use BreakPoints (advanced) or print the part out, like this:

local appearanceModel = game.Players:GetCharacterAppearanceAsync(120338859) --my character
local parts = appearanceModel:GetChildren() --descendents


for i, part in ipairs(parts) do
    print(part.Name, part.ClassName, part:GetFullName()) --NEW
	if part:IsA("BasePart") then
        print("Part: " part:GetFullName().. " : is a real Part")
	end
end

Try doing an else statement printing what the type of data parts is
else
print(typeof(parts))

if it doesn’t return any that are a base part/ mesh part/ part then it is something to do with the asynchronous method

Okay, I just made a weird discovery. If your character is wearing no hats it will for whatever reason not load your body parts. But the parts do not get anchored sadly.

Idk, sorry. Its up on you (but yes, its weird). Can you say us, what the script prints out?