Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 answers

✓ Accepted answer

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)

1 comment

0

tysm, i already knew how to do click detectors i just needed some help changing the properties of ALL children of an object.

do this

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

This discussion is preserved as it was. New answers, comments, and votes are closed.