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

Click a model, and its childrens' transparency will become 1?

I was trying to make a script that when you click the model that the script is placed in, the childrens' (parts') transparency will change to 1. Unfortunately, I didn't know what to put after I said "script.Parent:GetChildren()". Am I supposed to put a code line that changes the transparency of the children next to the code, or inside the parenthesis? Here's what I did:

function onClicked()
script.Parent:GetChildren()
-- what should go here?
-- Trying to make it so that when the model is clicked, the childrens' transparency will change to 1
end 

script.Parent.ClickDetector.MouseClick:connect(onClicked)

I'm not sure what I did wrong, and some help would be very appreciated.

1 answer

✓ Accepted answer

The :GetChildren() method returns a table of the parent's children. To make each child's transparency 1, you need to loop through the table. The easiest way to do this is with a for loop.

function onClicked()
	for i, v in pairs(script.Parent:GetChildren()) do
		v.Transparency = 1
	end
end 

script.Parent.ClickDetector.MouseClick:connect(onClicked)

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