Help with for loops on a child of :GetChildren

The title is confusing so I will briefly explain this. Basically, in the explorer, I have a hitbox part, then some attachments, and multiple particles within those attachments sporadically placed around the hitbox. To prevent lag, I want to make it so that the particles only start when the player touches the part. Here is my script so far but it just stops at the second for loop.

script.Parent.Touched:Connect(function(hit)
	if game.Players:FindFirstChild(hit.Parent.Name) then
		for i,v in pairs(script.Parent.Parent.Hitbox:GetChildren()) do
			if v:IsA("Attachment") then
				for o,b in pairs(v:FindFirstAncestorWhichIsA("Attachment"):GetChildren()) do
					if b:IsA("ParticleEmitter") then
						b.Enabled = true
					end
				end
			end
		end
	end
end)

Maybe something like this instead:

script.Parent.Touched:Connect(function(hit)
	if game.Players:FindFirstChild(hit.Parent.Name) then
		for _, item in pairs(script.Parent.Parent.Hitbox:GetDescendants()) do
			if item:IsA("ParticleEmitter") then
				item.Enabled = true
			end
		end
	end
end)
1 Like

Tried it and it works great! Thank you so much!

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