Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

Server script:

function ObjectsPlace()
		for i = 1,Collected_Max.Value do -- An int value in a "values" folder in workspace
			FoundA = false
			repeat
			for _, v in pairs(Map_Folder:GetChildren()) do
			if v:IsA("Model") then
				for _, area in pairs(v:GetDescendants()) do
					if area:IsA("Part") and area.Name == "CTT" then
						local FindHasVal = area:FindFirstChild("Has")
						if FindHasVal.Value == false then --checks to see if "ObjectC" is at this "area"
							local ObjectC = Instance.new("Part",Map_Folder)
							ObjectC.BrickColor = BrickColor.new("Really black")
							ObjectC.Anchored = true
							ObjectC.CanCollide = false
							ObjectC.Locked = true
							ObjectC.Size = Vector3.new(0.34, 0.98, 0.95)
							ObjectC.Material = Enum.Material.Granite
							ObjectC.Name = "Object_Collectable"
							ObjectC.CFrame = area.CFrame
							FindHasVal.Value = true
							FoundA = true
							print("good")
							else
						end
					end
				end
			end		
			end
			wait()
			until 
			FoundA == true
		end
		print("DONE LL")
end

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?

7 comments

0

So looks like FoundA never equals true. You should fix that. Which probably means that FindHasVal.Value never equals false.

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.

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.

0

Does good print in the output?

0

@SethHeinzman Yeah, everything seems good, but I don't know why it's not ending.

0

Put until and FoundA = true on the same line

0

You could say repeat wait() until function() And make the function include the for loops and return the value of FoundA

1 answer

✓ Accepted answer
repeat wait() until functionName()  == true

function functionName()
            for _, v in pairs(Map_Folder:GetChildren()) do
	            if v:IsA("Model") then
	                for _, area in pairs(v:GetDescendants()) do
	                    if area:IsA("Part") and area.Name == "CTT" then
	                        local FindHasVal = area:FindFirstChild("Has")
	                        if FindHasVal.Value == false then --checks to see if "ObjectC" is at this "area"
	                            local ObjectC = Instance.new("Part",Map_Folder)
	                            ObjectC.BrickColor = BrickColor.new("Really black")
	                            ObjectC.Anchored = true
	                            ObjectC.CanCollide = false
	                            ObjectC.Locked = true
	                            ObjectC.Size = Vector3.new(0.34, 0.98, 0.95)
	                            ObjectC.Material = Enum.Material.Granite
	                            ObjectC.Name = "Object_Collectable"
	                            ObjectC.CFrame = area.CFrame
	                            FindHasVal.Value = true
	                            print("good")
FoundA = true
					return FoundA
	                            else
	                        end
	                    end
	                end
            end 
return false
end

Something like that

1 comment

0

This is a bit messy, but it works! Thank you so much!! :D

This discussion is preserved as it was. New answers, comments, and votes are closed.