How can I make the debris shrink at the same time?

So the script in the video is the script for the debris, but I have no idea why it doesn’t shrink the cubes at the same time. Any ideas on how to solve that?

Here is the code:

wait(1)
local model = script.Parent
local debris = model.Debris
print(debris)
local max = 0

for _, v in pairs(debris:GetChildren()) do
	if not v:IsA("BasePart") then continue end
	
	print(v)
	
	for i = 1, 25 do
		v.Size -= Vector3.new(0.01,0.01,0.01)
		wait()
	end
	v:Remove()
end
1 Like

Try wrapping your second for loop in a coroutine or task.spawn

1 Like

Uhhh, what is that? I have no idea what that is

task.spawn(function()
    --// your for loop + v:Remove()
end)

OR

coroutine.wrap(function()
    --// your for loop + v:Remove()
end)

Hi!

I would suggest that you use TweenService :slight_smile:

Let me know if you have questions about what some of it does.

local TweenService = game:GetService("TweenService")

local Info = TweenInfo.new(1,Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0)

for _, v in pairs(debris:GetChildren()) do
	if v:IsA("BasePart") then
		spawn(function()
			local Tween = TweenService:Create(v,Info,{Size = Vector3.new(0.01,0.01,0.01)})
			Tween:Play()
			Tween.Completed:Wait()
			local Tween = TweenService:Create(v,Info,{Transparency = 1})
			Tween:Play()
			Tween.Completed:Wait()
			v:Remove()
		end)
	end
end
1 Like

well, I pasted the code into the script but, I get errors at Tween:Play(), saying that it expected to close {
at line 29.

I updated it while you copied it, try again. :slight_smile:

Yeeees! thank you it works perfectly!

The second tween that sets transparency might not be needed due to the size of your parts.

1 Like