I came up with this script so that it can find any brick name"Blink" to change its Transparency. The problem is that only one of the part name"Blink" changes its Transparency. Any Suggestions or tips?
Eyes = script.Parent:FindFirstChild("Blink") while true do Eyes.Transparency =0 wait(.3) Eyes.Transparency =1 wait(5) end
When trying to make something occur to multiple parts, you can't just name them all the same name then change the transparency of that parts name expecting to change every part with the same name. Lua doesn't do this and what I'd say the best way to do this is a generic for loop.
First, we need to get a collection of the parts. I will assume that script.Parent
is the Model for you.
To get the collection, we use GetChildren
.
Now, look in the bellow script for what you'll do and an explanation at the bottom.
BlinkParts = script.Parent:GetChildren() while true do for iterator, Part in pairs(BlinkParts) do if Part.Name == "Blink" then Part.Transparency = 0 wait(0.3) Part.Transparency = 1 wait(5) end end end
Yes, we still need a while loop to continuously run the blinking. I also made a Variable at the very top (BlinkParts) and you'll see I used it where my for loop starts. That argument (in parenthesis) is basically letting the script know what it's looking through to find Part
.
After, I am making a check on that parts name to see if it's the part you want to change, Blink. If we didn't use that check, lets say we have a part named PrettyPart, that would also change along with anything else.
The rest is what you seem to understand.
My above script will go eye to eye. This may not be what you want it to do, so how can you make them both go at the same time? A really is way to to make 2 scripts inside of each Blink part. The script which I believe you could make yourself is bellow, if you need an explanation on it, comment, otherwise I assume you already understand it.
while true do script.Parent.Transparency = 0 wait(0.3) script.Parent.Transparency = 1 wait(5) end