Is it possible to make a loop set a bool to true once its finished

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Make the loop shown below run a
local tweenService = game:GetService("TweenService")

local growtime = 20

local maxheight = math.random(3,7)

for i, v in pairs(script.Parent:GetChildren()) do
	if v.Name == "Part" then
		task.wait(math.random(0.2,0.7))
		local tweenInfo = TweenInfo.new(growtime, Enum.EasingStyle.Linear)
		local goal = {Size = Vector3.new(0.125, maxheight, 0.125)}
		local tween = tweenService:Create(v, tweenInfo, goal)
		tween:Play()
	end
end

I tried adding a print after the second to last end hoping it would only run once they were all finished but It ran every time.

1 Like
local tweenService = game:GetService("TweenService")

local growtime = 20

local maxheight = math.random(3,7)

for i, v in pairs(script.Parent:GetChildren()) do
	if v.Name == "Part" then
		task.wait(math.random(0.2,0.7))
		local tweenInfo = TweenInfo.new(growtime, Enum.EasingStyle.Linear)
		local goal = {Size = Vector3.new(0.125, maxheight, 0.125)}
		local tween = tweenService:Create(v, tweenInfo, goal)
		tween:Play()
		tween.Completed:Wait()
		--BOOL
	end
end

You need to use Tween.Completed
In this case, the script will wait until tween is finished
If you need this cycle to continue you can use

		tween.Completed:Connect(function()
			
		end)
2 Likes

This causes the loop to pause between tweening each part, I need the parts to all tween at the same time. The script is growing wheat, and its made up of parts and I need the player to be able to harvest the crop after all of the parts grow

Then use this option

local tweenService = game:GetService("TweenService")

local growtime = 20

local maxheight = math.random(3,7)

for i, v in pairs(script.Parent:GetChildren()) do
	if v.Name == "Part" then
		task.wait(math.random(0.2,0.7))
		local tweenInfo = TweenInfo.new(growtime, Enum.EasingStyle.Linear)
		local goal = {Size = Vector3.new(0.125, maxheight, 0.125)}
		local tween = tweenService:Create(v, tweenInfo, goal)
		tween:Play()
		tween.Completed:Connect(function()
			--BOOL
		end)
	end
end
1 Like

Ooh thank you, I diddnt notice that in the original comment.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.