i don't want to go through each and every part and make it transparent. Can someone help me?~~~~~~~~~~~~~~~~~ local model = workspace.Model ~~~~~~~~~~~~~~~~~
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
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
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.