For loop is going through each "BasePart" in a table 1 by 1

I am making an Axe and Tree system, I want it so after you have cut down the tree all the parts fall to the floor (Unanchor) and go transparent etc, but each part is going through all the unanchoring and transparency changing 1 by 1 instead of all at once, is there a way to stop this and make it happen all at once, even by changing the for loop to something else? The script is a local script inside an Axe tool in StarterPlayer.

for index, v in pairs(game.workspace.Tree:GetDescendants()) do
			if v:IsA("BasePart") then
				v.Anchored = false
				v.Transparency = 0.2
				task.wait(3)
				v.Transparency = 1
				v.CanCollide = false
			end
		end

Pass the loop body as a function to task.spawn.

for index, v in pairs(game.workspace.Tree:GetDescendants()) do
	if not v:IsA("BasePart") then
		continue
	end
	
	task.spawn(function()
		v.Anchored = false
		v.Transparency = 0.2
		task.wait(3)
		v.Transparency = 1
		v.CanCollide = false
	end)
end
2 Likes

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