What I am trying to get is the 3 blue dots to come in and out of visibility. So the first one would become visibile, then as it fades, the second one comes visible, and vice versa and it just loops over.
for _, v in pairs(intro:GetChildren()) do
if v:IsA('ImageLabel') then -- the 3 dot images
for i = 1, 0, -0.05 do
v.ImageTransparency = i
wait()
for i = 0, 1, 0.05 do
v.ImageTransparency = i
wait()
end
end
end
end
This just cause the first dot to flash basically, instead of moving onto the next dot
This is basically what I am aiming for
Add a wait() between each time the image’s transparency is going to change.
I had a problem similar to this with a fading Gui and adding wait() inbetween each time changing the transparency works.
You’ll want to wrap the code inside the for loop in a spawn() and then at the end of the code (after the end of the spawn()) You’ll have to change the time in the wait till the effect looks like you want.
spawn(function()
for _, v in pairs(intro:GetChildren()) do
if v:IsA('ImageLabel') then -- the 3 dot images
for i = 1, 0, -0.05 do
v.ImageTransparency = i
wait()
for i = 0, 1, 0.05 do
v.ImageTransparency = i
wait()
end
end
end
end
wait()
end)
Not entirely sure how that makes much of a difference??
With your original code the first dot will change transparency, and it’ll wait until it’s fully done until going onto the next dot.
With spawn, wrapping the transparency code in a spawn() means that they’ll all run at the same time. You obviously don’t want them to run at the EXACT time because you want the effect like in the gif you provided. So you add a wait() after the spawn so it’ll wait a tiny amount before going onto the next one to create the effect like in your gif.
In your innermost loop you are overriding the value of i which is being used by the loop before. so when the inner loop finishes ‘i’ has been reset to 1. So your for middle for loop is acting like a while loop.
I would just suggest using the Delay function. After you check if v is an image label, put the fading code into a function and pass it into the Delay function.
Delay(TimeToDelay, function()
-- Fading code here
end)
To calculate the TimeToDelay, you can just take the number of the dot, subtract 1 (so that the first one starts right away) and multiply it by 0.6 (since thats about how long it takes before a dot starts fading out).
To know which dot is what number, replace the _ in the pairs loop with i (or whatever) and use that. So essentially TimeToDelay = (i - 1) * 0.6
That will fire off the code for each dot at the correct time.
for _, v in pairs(intro:GetChildren()) do
spawn(function()
if v:IsA('ImageLabel') then -- the 3 dot images
for i = 1, 0, -0.05 do
v.ImageTransparency = i
wait()
for i = 0, 1, 0.05 do
v.ImageTransparency = i
wait()
end
end
end
end)
wait()
end
for _, v in pairs(intro:GetChildren()) do
spawn(function()
wait(1)
if v:IsA('ImageLabel') then -- the 3 dot images
for i = 1, 0, -0.05 do
v.ImageTransparency = i
wait()
for i = 0, 1, 0.05 do
v.ImageTransparency = i
wait()
end
end
end
end)
end
local dots = {} --the 3 dot images
for _, v in pairs(intro:GetChildren()) do
if v:IsA('ImageLabel') then
table.insert(dots,#dots+1,v)
end
end
for d = 1, #dots do
for i = 1, 0, -0.05 do
dots[d].ImageTransparency = i
if d>1 then
dots[d-1].ImageTransparency = 1-i
else
dots[#dots].ImageTransparency = 1-i
end
wait()
end
end
Although you probably are better off using tween service.
local TweenService = game:GetService("TweenService")
local tweenTime = 0.75 --How long you want the dots to fade in/out
for _, v in pairs(intro:GetChildren()) do
if v:IsA('ImageLabel') then v.ImageTransparency = 1 end
end
local tweenInfo = TweenInfo.new(
tweenTime, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
true -- Reverses (tween will reverse once reaching it's goal)
)
for _, v in pairs(intro:GetChildren()) do
if v:IsA('ImageLabel') then
TweenService:Create(v,tweenInfo,{ImageTransparency=0}):Play()
wait(tweenTime)
end
end