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
4 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
4 years ago
local model = workspace.Model
for i,v in pairs(model:GetChildren()) do
if v:IsA("Part") then
v.Transparency = 1
end
end
end

it goes through all children until no more children

0
or you could use GetDescendants to go through everything in the model mybituploads 304 — 4y
0
true KDarren12 705 — 4y
Ad
Log in to vote
1
Answered by
sleazel 1287 Moderation Voter
4 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:

local model = workspace.Model

for i,v in pairs(model:GetDescendants()) do
    if v:IsA("BasePart") or v:IsA("Decal") then
        v.Transparency = 1
    end
end

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:

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

Have a nice scripting session

0
dont mind at all KDarren12 705 — 4y
Log in to vote
0
Answered by
oreoollie 649 Moderation Voter
4 years ago
Edited 4 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:

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

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