As the title states:
My repeat until loop does not stop after transparency is set to 1.
How can I fix this? Any help would be appreciated.
I want the script to simply add 0.05 transparency to the texture of the part every 0.01 seconds. Then, after the transparency reaches 1, I want it to take away transparency from the part's texture every 0.01 seconds until it reaches 0.
Script:
PartBoard = game.Workspace.PartBoard Part = PartBoard.Part Part2 = PartBoard.Part2 Part3 = PartBoard.Part3 Part4 = PartBoard.Part4 Part5 = PartBoard.Part5 while wait() do wait (5) if Part.BloxyCola.Transparency == 0 then repeat wait (0.01) Part.BloxyCola.Transparency = Part.BloxyCola.Transparency + 0.05 Part2.BloxyCola.Transparency = Part2.BloxyCola.Transparency + 0.05 Part3.BloxyCola.Transparency = Part3.BloxyCola.Transparency + 0.05 Part4.BloxyCola.Transparency = Part4.BloxyCola.Transparency + 0.05 Part5.BloxyCola.Transparency = Part5.BloxyCola.Transparency + 0.05 until Part.BloxyCola.Transparency == 1 end wait (5) if Part.BloxyCola.Transparency == 1 then repeat wait (0.01) Part.BloxyCola.Transparency = Part.BloxyCola.Transparency - 0.05 Part2.BloxyCola.Transparency = Part2.BloxyCola.Transparency - 0.05 Part3.BloxyCola.Transparency = Part3.BloxyCola.Transparency - 0.05 Part4.BloxyCola.Transparency = Part4.BloxyCola.Transparency - 0.05 Part5.BloxyCola.Transparency = Part5.BloxyCola.Transparency - 0.05 until Part.BloxyCola.Transparency == 0 end end
While using a while loop you dont have to use repeat until, plus its better to use if statements then break.
The best way to shorten and fix your code are to: Add a table for bloxycolas, add functions for adding/removing transparency, and adding loops for using those functions. I didn't want to mess with your waits since I didn't know if they were for something, so you can change those. Here's what your code should look like:
PartBoard = game.Workspace.PartBoard local BCs = {} for _, v in pairs(PartBoard:GetChildren()) do table.insert(BCs, v:GetChildren()) end local B1 = PartBoard.Part.BloxyCola function removeTrans(part) part.Transparency = part.Transparency - 0.05 end function addTrans(part) part.Transparency = part.Transparency + 0.05 end while true do wait (5) if B1.Transparency == 0 then while B1.Transparency <1 do for _,v in ipairs(BCs) do addTrans(v) wait(0.01) end end end wait (5) if B1.Transparency == 1 then while B1.Transparency >0 do for _,v in ipairs(BCs) do removeTrans(v) wait(0.01) end end end end