Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
4 years ago
Edited 4 years ago

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.

0
Well, all my parts are welded so the output says: "Material is not a valid member of WeldConstraint" ArcanZus 61 — 4y
0
Try the updated code Benbebop 1049 — 4y
0
@Benbebop Try adding a PCall functon at line 4, or checking if the part can have its material changed Leamir 3138 — 4y
0
I'll try! ArcanZus 61 — 4y
View all comments (2 more)
0
It worked, thanks! ArcanZus 61 — 4y
0
Why a pcall? Simple IsA check is needed... incapaz 195 — 4y
Ad

Answer this question