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

How do I get the parts inside of an object and change their properties?

Well, I'm trying to use "GetDescendants" but whenever I try to change the properties it won't work. Inside the object there are some other parts, 3 audios and 1 BoolValue. I wan't to change the material of those parts without having to write each one of them down.

I'll give an example of what I'm trying to do

local all = game.Workspace.Object:GetDescendants()
all.Material = Enum.Material.ForceField

1 answer

✓ Accepted answer

You need to set each object individually if you are using a table.

local all = game.Workspace.Object:GetChildren("Part")

for i=1,#all do
	all[i].Material = Enum.Material.ForceField
end

for i=1,#var do will repeat that line for however many variables are in the table var, #var is a count of how many variables are in the table. i increases by one each loop. all[i] will go through each item on the table. And from what I know "Part" is the name or type of instance you are getting.

6 comments

0

Well, all my parts are welded so the output says: "Material is not a valid member of WeldConstraint"

0

Try the updated code

0

@Benbebop Try adding a PCall functon at line 4, or checking if the part can have its material changed

0

I'll try!

0

It worked, thanks!

0

Why a pcall? Simple IsA check is needed...

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