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

How do I do something to all children of an object?

Asked by
8jxms 9
1 year ago

I want to make it so that all parts in a model turn transparent when you click something.

2 answers

Log in to vote
0
Answered by
Hypcros 15
1 year ago

You can turn all parts in a model transparent by using click detectors. (Linked here: https://developer.roblox.com/en-us/api-reference/class/ClickDetector )

here is a simple script I made...

local folder = game.Workspace.PartFolder
local clickDetector = script.Parent.ClickDetector



function onMouseClick()
    for i, v in pairs(folder:GetChildren()) do
        if v.Transparency == 1 then
            v.Transparency = 0
        else
            v.Transparency = 1
        end
    end
end


clickDetector.MouseClick:connect(onMouseClick)

This script gets the children of an object, checks if they are transparent or not, and does the opposite transparency (this is just a simple toggle, if you dont want it to toggle then remove the if statement and just put v.Transparency = 1). Since you wanted it to be if someone clicks an object, I used a clickDetector (Check the link I added for more info on those). For a click detector to work the part you want to click must have a click detector as a child.

(Hopefully this explains enough to get you situated, I am pretty bad at explaining so I would recommend checking youtube for click detector videos or check the roblox developer wiki)

0
tysm, i already knew how to do click detectors i just needed some help changing the properties of ALL children of an object. 8jxms 9 — 1y
Ad
Log in to vote
0
Answered by 1 year ago

do this

local MODEL = game.Workspace.model
local children = MODEL:GetChildren()
for i, v, in pairs(children) do
    v.Transparency = 1
end

Answer this question