Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How can i change the material of certain Children with ClassName?

Hi, i did a script that when put inside a Character, it's suppose to remove his clothes and put his skin into rock using Material, i am using a R15 Rigs so the body part are MeshPart Here's my script:

local shirt = script.Parent.Shirt
local pants = script.Parent.Pants

wait(2)
shirt.Parent = nil
pants.Parent = nil

local child = script.Parent:GetChildren()
local brick = child.Material
wait(1)
if (child.className == "MeshPart") then 
	brick = Enum.Material.Concrete
end

Weirdly, it don't seem to work, i am not a professional with script so i can't quite figure out why.

1 answer

✓ Accepted answer

You can use IsA to check the part type

local shirt = script.Parent.Shirt
local pants = script.Parent.Pants

wait(2)
shirt.Parent = nil
pants.Parent = nil

local child = script.Parent:GetChildren()
local brick = child.Material
wait(1)
if child:IsA(“MeshPart”) then 
    brick = Enum.Material.Concrete
end

2 comments

0

Thank you helpful, will use IsA instead but did i messed something else that im unaware?

0

Um I don’t think so

This discussion is preserved as it was. New answers, comments, and votes are closed.