How come this doesn't work?

I’m trying to add to the transparency of all the frames inside of this frame without writing it over and over again, but it doesn’t seem to work. If I keep the last two lines, it’s extremely laggy but still doesn’t do anything. Help?

for i, v in pairs(CurrentRoleEquipment:GetChildren()) do
			if v:IsA("Frame") then
				while true do
				v.BackgroundTransparency = v.BackgroundTransparency - 0.05 
				task.wait()
				repeat
				until v.BackgroundTransparency == 0.6
			end
		end
	end	

You’re adding too many loops that you don’t need.

repeat and while both loop so you only need one

if v:IsA("Frame") then
  repeat
    v.BackgroundTransparency = v.BackgroundTransparency - 0.05 
    task.wait()
  until v.BackgroundTransparency == 0.6
end

also I’m guessing if you want them all to decrease at once you can learn how to use a CanvasGroup or script it manually.

if v:IsA("Frame") then
  task.defer(function()
    repeat
      v.BackgroundTransparency = v.BackgroundTransparency - 0.05 
      task.wait()
    until v.BackgroundTransparency == 0.6
  end)
end

task.defer allows a function to run alongside the rest of the script so it doesnt wait for the UI to fade.

But in conclusion you could use TweenService to automate all of this

2 Likes

Is there a way where it could all happen at once? It does it one by one which looks messy.

Yea I mentioned that in the post. Use a CanvasGroup or the second block of code instead.