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.
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:
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.
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
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.