TouchInterest not being added to KillBricks

  1. What do you want to achieve?
    I want to have multiple (42 to be exact) killBricks with 1 script so it is efficient.

  2. What is the issue?
    My script wont add touch interests to all of the bricks, only a few get the interest.

  3. What solutions have you tried so far?
    I’ve tried searching for someone with a similar problem but couldn’t find any results.

-- there is 42 bricks + 1 script
local bricks

repeat bricks = script.Parent:GetChildren()
task.wait(.25)
until #bricks == 43


for i, v in ipairs(bricks) do
	if not v:IsA("Part") then return end
	v.Touched:Connect(function(hit)
		local hum = hit.Parent:FindFirstChild("Humanoid")
		if not hum then return end
		
		hum.Health = 0
	end)
end

Result
image

1 Like

The problem could be the fact that you’re using “return” in your code. which breaks out of the loop completely, you should use “continue” instead

3 Likes

Never knew that such a thing existed, but thanks it works now I will also look into this.