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

How to make certain parts of a loop repeat before other parts finish?

Asked by
manith513 121
2 years ago

I'm trying to make it where a house disappears part by part by increasing the transparency of the part, but I also want this affect to apply to up to 4 other parts on the house before they are finished.

01local house = script.Parent
02local runservice = game:GetService("RunService")
03 
04local debounce = 0
05 
06for i,v in pairs(house:GetChildren()) do
07    if v:IsA("Part") then
08        if debounce < 4 then
09            debounce = debounce + 1
10                    for i = 1,10 do
11 
12                        v.Transparency = v.Transparency + 0.1
13 
14 
15                        wait()
View all 22 lines...

I want the first four parts that the first for loop calls upon, to all start disappearing 0.1 seconds from each other, and I don't want more parts to start disappearing until the first one out of these four have disappeared and so on. I know in my code the loop does each step once before repeating so it wouldn't work but I'm not sure how to repeat certain parts before other parts have finished. Help would greatly be appreciated!

2 answers

Log in to vote
1
Answered by
NykoVania 231 Moderation Voter
2 years ago
Edited 2 years ago

I'm not sure if this helps, but if you use a repeat until loop you can wait until something is true or etc.

1local a = false
2 
3repeat wait()
4-- code here
5until a == true
0
Yes! I used this for my debounce so that when the function was called on repeatedly with spawn, it would wait before progressing, thanks for your help. manith513 121 — 2y
Ad
Log in to vote
0
Answered by
manith513 121
2 years ago

I figured it out, I used repeat wait() until thanks to Nyko and paired it with

1spawn(function()
2 
3end)

which I didn't know about but let's you call on functions to start again without waiting for them to finish.

My finished code paired with this that worked for me:

01local house = script.Parent
02local runservice = game:GetService("RunService")
03 
04local debounce = 0
05 
06function mightwork(part)
07repeat  wait() until debounce < 4
08    print("Started 1")
09    if debounce < 4 then
10        debounce = debounce + 1
11 
12 
13        for i = 1,25 do
14 
15 
View all 40 lines...

Thank you Nyko since your answers lead me to what I was looking for.

Answer this question