Tween not running unless there are 0 wait()'s

Ive been having this strange issue with my tween only running if I dont have any wait()'s, then it runs exactly 12 times 100% of the time
image

here is an example of it not working:

local PrimaryPartDestination = Vector3.new(x, y, z + 2.5)

local clicked = false
script.Parent.ClickDetector.MouseClick:Connect(function()
if not clicked then
		clicked = true
		for i,Part in pairs(Model:GetChildren()) do
			local Tween = TweenService:Create(Part,Info,{CFrame = CFrame.new((Part.Position-Model.PrimaryPart.Position)+PrimaryPartDestination)})
			Tween:Play()
			playquit:Play()
			print("test")
			repeat task.wait() until not playquit.IsPlaying
			print("anim done")
			local bomb = Instance.new("Explosion")
			bomb.Position = Vector3.new(dumx + 20, dumy, dumz + 10.5)
			bomb.BlastRadius = 2
			bomb.Parent = workspace
			task.wait()
			script.Parent.Parent.Parent.DummyTest:Destroy()
			clicked = false
			
		end
	end
	
end)

image


and here is it working

local PrimaryPartDestination = Vector3.new(x, y, z + 2.5)

local clicked = false
script.Parent.ClickDetector.MouseClick:Connect(function()
if not clicked then
		clicked = true
		for i,Part in pairs(Model:GetChildren()) do
			local Tween = TweenService:Create(Part,Info,{CFrame = CFrame.new((Part.Position-Model.PrimaryPart.Position)+PrimaryPartDestination)})
			Tween:Play()
			playquit:Play()
			print("test")
			--repeat task.wait() until not playquit.IsPlaying
			--print("anim done")
			--local bomb = Instance.new("Explosion")
			--bomb.Position = Vector3.new(dumx + 20, dumy, dumz + 10.5)
			--bomb.BlastRadius = 2
			--bomb.Parent = workspace
			--task.wait()
			--script.Parent.Parent.Parent.DummyTest:Destroy()
			--clicked = false
			
		end
	end
	
end)

if I completely get rid of the wait it cant run 12 times and doesn’t run the tween. Ive been struggling with this for almost a day it would be great if anyone can point out my mistake. Thanks

ive run other tests with waits and the same thing happened

all of my other tween info is above this thats not the issue

I think you are not familiar with how the “for” line of code works.

Basically, it will loop through the code multiple times. In your case, once for each child in a model. It runs the code once for each child, but does them one at a time, so if you have a “wait()” it will not get to the next one until the last one has finished.

I think you have some code inside the for-loop, when really you want it outside of the for-loop.

I didnt even realize that
This is most likely the issue ill try to fix this then award your solution if it worked

thanks

1 Like