Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

repeat until loop does not stop after transparency = 1? What is wrong? How can I fix this?

Asked by 3 years ago

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
0
I don’t know how to fix this, but i would use i,v pairs to make life. easier jaisonDXYX 24 — 3y

2 answers

Log in to vote
0
Answered by 3 years ago

While using a while loop you dont have to use repeat until, plus its better to use if statements then break.

0
or watch a video by alvinblox on repeating loops) KamKam_AJHasBeenBan 37 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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

Answer this question