For some reason, instead of selecting all parts and editing them at once in unison, it decides to select one and then go to the next instead of editing the properties of all parts instantly/gradually. It’s sort of hard to explain but this is what I’m stuck on:
wait(5)
print("check")
for _,Part in pairs(script.Parent:GetDescendants()) do
if Part:IsA("BasePart") then
for i = 1, 6 do
Part.Transparency = Part.Transparency -0.05
wait(0.1)
end
end
end
Essentially like I said, this only selects one part at a time and edits it, whereas I want all parts to be selected and edited at once. Any ideas?
Since you are yielding in your numeric loop you need to wait for that one to finish so the generic for loop can go another cycle. You can use coroutine.wrap to do them at about the same time
if Part:IsA("BasePart") then
coroutine.wrap(function()
for i = 1, 6 do
Part.Transparency = Part.Transparency -0.05
wait(0.1)
end
end)()
end
You can either create a tween for each one with TweenService and play them all simultaneously or you can use coroutines:
wait(5)
print("check")
for _,Part in pairs(script.Parent:GetDescendants()) do
if Part:IsA("BasePart") then
coroutine.wrap(function()
for i = 1, 6 do
Part.Transparency = Part.Transparency -0.05
wait(0.1)
end
end)()
end
end
Considering I’ve looked at thousands of lines of code for years in Studio, I’m suprised I’ve never heard of coroutines before. I’m quite a novice and I’ve recently been picking up speed in learning Lua for the past couple of months so it is very nice to see someone introduce a new part of Lua to me. I will definitely look into coroutines. Thank you for the solution!