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

how to make ALL parts of a model fully tranparent?

Asked by
luaa233 37
5 years ago

i don't want to go through each and every part and make it transparent. Can someone help me?~~~~~~~~~~~~~~~~~ local model = workspace.Model ~~~~~~~~~~~~~~~~~

3 answers

Log in to vote
0
Answered by
KDarren12 705 Donator Moderation Voter
5 years ago
1local model = workspace.Model
2for i,v in pairs(model:GetChildren()) do
3if v:IsA("Part") then
4v.Transparency = 1
5end
6end
7end

it goes through all children until no more children

0
or you could use GetDescendants to go through everything in the model mybituploads 304 — 5y
0
true KDarren12 705 — 5y
Ad
Log in to vote
1
Answered by
sleazel 1287 Moderation Voter
5 years ago

I will expand on KDarren12 answer, hope you don't mind mate :) IsA("Part") will not detect mesh parts (R16 for example). You should use IsA("BasePart") instead. Also if your model contains decals they will not be made transparent. Finally children of the model may have their own children and they will be omitted by the loop. Use GetDescendants() to avoid that:

1local model = workspace.Model
2 
3for i,v in pairs(model:GetDescendants()) do
4    if v:IsA("BasePart") or v:IsA("Decal") then
5        v.Transparency = 1
6    end
7end

If by any chance you are making characters transparent, changing them back needs one more consideration. A part called HumanoidRootPart is meant to be transparent:

1--reverse process
2for i,v in pairs(model:GetDescendants()) do
3    if (v:IsA("BasePart") or v:IsA("Decal")) and v.Name ~= "HumanoidRootPart" then
4        v.Transparency = 0
5    end
6end

Have a nice scripting session

0
dont mind at all KDarren12 705 — 5y
Log in to vote
0
Answered by
oreoollie 649 Moderation Voter
5 years ago
Edited 5 years ago

Your best bet would be to loop through the descendants of the model then check if they're of class BasePart (so unions and such are affected). This is better than looping through the children because the children of any folders, submodels, etc will also be indexed. Here's how you would do that:

1local model = workspace.Model
2for _, v in ipairs(model:GetDescendants()) do
3    if v:IsA("BasePart") then
4        v.Transparency = 1
5    end
6end

I'm not sure what you're trying to do, but it might be a better choice to simply move the model ReplicatedStorage if you're simply trying to remove it from the game temporarily.

If my answer solved your problem please don't forget to upvote and accept it.

Answer this question