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

How do you make a model with a lot of parts invisible with only one line of code?

Asked by 2 years ago

I need to make it so that a model with 85 parts becomes completely invisible. I wanna see if there's a way to do this with only one line of code so that I don't have to type game.Workspace.MENUCHARS.BLAHBLAH.BLAHBLAH.Transparency = 1 eighty five times. I've tried blahblah = game.Workspace.menuchars.BLAHBLAH:GetChildren() and then blahblah.Transparency = 1, but it of course, didn't work.

2 answers

Log in to vote
0
Answered by 2 years ago

You can accomplish this with pairs

Code example:

local menuChars = game.workspace:WaitForChild("MenuChars") -- where ever your model is
for index, value in pairs(menuChars:GetChildren()) do -- loop through everything in the model
    if value:IsA("BasePart") then -- make sure its a part
        value.Transparency = 1 -- set transparency
    end
end
0
GetChildren returns an array, so you should use ipairs as it is less resource intensive. Benbebop 1049 — 2y
0
Oh really. Never knew that. So you can do ipairs(menuChars) and it will do the same as in pairs(menuChars) while being less resource intensive? SimpleFlame 255 — 2y
0
Oh really, I never knew that. So you can do ipairs(menuChars) and it will do the same as in pairs(menuChars) while being less resource intensive? SimpleFlame 255 — 2y
Ad
Log in to vote
0
Answered by
Aimarekin 345 Moderation Voter
2 years ago

Use loops, like this:

for _item in pairs(Object:GetChildren()) do
    item.Transparency = 1
end

Answer this question