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

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

Asked by 4 years ago

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

Log in to vote
0
Answered by
Klamman 220 Moderation Voter
4 years ago

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)

Ad

Answer this question