How come the text becomes transparent instantly instead of waiting a bit?
function onMouseButton1Click() for i=0, 1, 0.1 do for i,v in pairs(script.Parent.Parent:GetChildren()) do if v:IsA('TextButton') then v.BackgroundTransparency = i script.Parent.Parent.TextLabel.TextTransparency = i end end wait(0.03125) end end script.Parent.MouseButton1Click:connect(onMouseButton1Click)
Thanks!
I have a couple of suggestions:
0.5: Try using less exact numbers. the last 3 digits make an unseeable difference.You can see it but it is repeat really= really + 1 until really = math.huge
unnecessary and hard to see.
Coding methods:
You can use "Ctrl + H" to use the "replace tool* for replacing Granny with whatever you want the variable to be called*
1: Organize the script. Just do a repeat/for loop. Ex:
local Granny = script.Parent.Parent function onMouseButton1Click() for i,v in pairs(Granny:GetChildren()) do if v:IsA('TextButton') then for i = 0, 1, .1 do v.BackgroundTransparency = i v.TextTransparency = i Granny.TextLabel.TextTransparency = 1 wait(.03) end end end end script.Parent.MouseButton1 Click:connect(onMouseButton1Click)
2: Courtine: This might work if the one above doesn't or if you prefer to use this.
local Granny = script.Parent.Parent local BackgroundTransparency = coroutine.wrap(function() for i,v in pairs(Granny:GetChildren()) do if v:IsA('TextButton') then for i = 0, 1, .1 do v.BackgroundTransparency = i wait(.03) end end end end) local TextTransparency1 = coroutine.wrap(function() for i,v in pairs(Granny:GetChildren()) do if v:IsA('TextButton') then for i = 0, 1, .1 do v.TextTransparency = i wait(.03) end end end end) local TextTransparency2 = coroutine.wrap(function() for i,v in pairs(Granny:GetChildren()) do if v:IsA('TextButton') then for i = 0, 1, .1 do Granny.TextLabel.TextTransparency = 1 wait(.03) end end end end) BackgroundTransparency() TextTransparency1() TextTransparency2()
If you need help, comment. If this helped, please accept this :D
For loops with waits will hold the other objects up. Each object will fade individually by the way you have the script set up. Not to mention, you code is inefficient. To increase the transparency of the objects, you really should be using a for loop.
With your script, we find two options. We can either flip the for loops, have the GetChildren table loop inside of the numeric for loop for transparency. Or we can use coroutines or the spawn function.
For my answer, I will just be using the first option. We will want to set up a for loop and use the variable to set the transparency. For loops have a third optional parameter that will allow you to change how they step. Within the for loop for our transparency, we will want to have a for loop with all objects in the GetChildren table. At that point, we can mess with the transparency and add a wait after we close the GetChildren table for loop.
function onMouseButton1Click() for i=0, 1, .1 do --We start off at zero, for everything from 0 up to 1 we will add .1 to i. for i,v in pairs(script.Parent.Parent:GetChildren()) do --We will go through all objects of the GetChildren table. v.BackgroundTransparency = i --Change transparency. v.TextTransparency = i script.Parent.Parent.TextLabel.TextTransparency = i end wait(.03125) --Now that we are done going through all objects in the table at this round, we can have a little wait before the next round. end end script.Parent.MouseButton1Click:connect(onMouseButton1Click)