Recently i’m trying to create an effect that makes base parts blink with transparency changing. I want all the parts called in the in pairs to blink all at the same time but the base parts seem to blink 1 at a time. Is there a in pairs of some kind that simulates all at the same time instead of individually?
For reference, here’s the code:
function changeTransparencyEffect()
if CTE_Debounce == true then
CTE_Debounce = false
for _,v in pairs(script.Parent.Parent.colorme:GetChildren())do
repeat
v.Transparency = v.Transparency+0.2
wait(0.1)
until v.Transparency >= 1
repeat
v.Transparency = v.Transparency-0.2
wait(0.1)
until v.Transparency <= 0
end
CTE_Debounce = true
end
end
The simplest solution is just to swap your loops. Right now your inner loop tweens teens transparency and the outer loop goes over all parts.
If you swap that to make the outer loop tween transparency then the inner loop to iterate over the parts and apply it it’ll fix your issue.
Also you’re using the wrong function; pairs is for dictionaries and mixed tables, but what you want is ipairs which is for arrays. This isn’t directly related to the issue but you should fix.
Alternatively, the best solution was what someone already mentioned of using TweenService.
Thank you for your suggestion. I’ll be sure to add that once I get my hands on a computer. I did try looking into tween service but I thought it was only for animating objects.
function changeTransparencyEffect()
if CTE_Debounce == true then
CTE_Debounce = false
for _,v in pairs(script.Parent.Parent.colorme:GetChildren()) do
spawn(function()game:GetService('TweenService'):Create(v,TweenInfo.new(1),{Transparency = 1}):Play()wait(1) game:GetService('TweenService'):Create(v,TweenInfo.new(1),{Transparency = 0}):Play()end)
end
CTE_Debounce = true
end
end