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

Repeat until loop doesn't seem to end, why?

Asked by 4 years ago
Edited 4 years ago

Server script:

01function ObjectsPlace()
02        for i = 1,Collected_Max.Value do -- An int value in a "values" folder in workspace
03            FoundA = false
04            repeat
05            for _, v in pairs(Map_Folder:GetChildren()) do
06            if v:IsA("Model") then
07                for _, area in pairs(v:GetDescendants()) do
08                    if area:IsA("Part") and area.Name == "CTT" then
09                        local FindHasVal = area:FindFirstChild("Has")
10                        if FindHasVal.Value == false then --checks to see if "ObjectC" is at this "area"
11                            local ObjectC = Instance.new("Part",Map_Folder)
12                            ObjectC.BrickColor = BrickColor.new("Really black")
13                            ObjectC.Anchored = true
14                            ObjectC.CanCollide = false
15                            ObjectC.Locked = true
View all 34 lines...

This is just a function that's called in another line, however, in the function the repeat loop doesn't seem to end. Anyone know how or why this is happening?

0
So looks like FoundA never equals true. You should fix that. Which probably means that FindHasVal.Value never equals false. SethHeinzman 284 — 4y
0
When you run the game, you can go in explorer and find "Has" and change it's value to false to see if it stops I think. SethHeinzman 284 — 4y
0
@SethHeinzman "Has" is set to false by default meaning that "FindHasVal.Value" is false. Another thing is that "FoundA" equals true after "ObjectC" has been made/placed, so I don't think that's the problem here. Player1_Joined 271 — 4y
0
Does good print in the output? SethHeinzman 284 — 4y
View all comments (3 more)
0
@SethHeinzman Yeah, everything seems good, but I don't know why it's not ending. Player1_Joined 271 — 4y
0
Put until and FoundA = true on the same line OhManXDXD 445 — 4y
0
You could say repeat wait() until function() And make the function include the for loops and return the value of FoundA SethHeinzman 284 — 4y

1 answer

Log in to vote
2
Answered by 4 years ago
Edited 4 years ago
01repeat wait() until functionName()  == true
02 
03function functionName()
04            for _, v in pairs(Map_Folder:GetChildren()) do
05                if v:IsA("Model") then
06                    for _, area in pairs(v:GetDescendants()) do
07                        if area:IsA("Part") and area.Name == "CTT" then
08                            local FindHasVal = area:FindFirstChild("Has")
09                            if FindHasVal.Value == false then --checks to see if "ObjectC" is at this "area"
10                                local ObjectC = Instance.new("Part",Map_Folder)
11                                ObjectC.BrickColor = BrickColor.new("Really black")
12                                ObjectC.Anchored = true
13                                ObjectC.CanCollide = false
14                                ObjectC.Locked = true
15                                ObjectC.Size = Vector3.new(0.34, 0.98, 0.95)
View all 29 lines...

Something like that

0
This is a bit messy, but it works! Thank you so much!! :D Player1_Joined 271 — 4y
Ad

Answer this question