How can I use the same script affect alot of parts?

Hey, I’m currently making a little game and have a kill brick script. This part will be used alot of times so I don’t want all of the parts having scripts inside of them. Would it be possible to tell these specific parts in a script and then execute the same script on the same event?
I don’t want the script to be in every part not only because how unorganized it is, but to prevent so many scripts doing the same thing and lagging the server.
Current kill brick script:

local debounce = true
script.Parent.Touched:Connect(function(Hit)
	if debounce == true then
		if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
			debounce = false
			Hit.Parent.Humanoid.Health = 0
			wait(1)
			debounce = true
		end
	end
end)

Anything helps, thanks!

Use collection service, you could use a plugin called tag editor, you could go to this devforum to learn more about tag editor and collection service, it’s really helpful. Check it out:

2 Likes

Just loop through all the parts. Have a folder with all of the kill bricks you want.

local Folder = --Put your folder with all of the kill bricks inside.
for _, KillBrick in pairs(Folder:GetChildren()) do
    local debounce = true
    KillBrick.Touched:Connect(function(Hit)
	if debounce == true then
		if Hit and Hit.Parent and Hit.Parent:FindFirstChild("Humanoid") then
			debounce = false
			Hit.Parent.Humanoid.Health = 0
			wait(1)
			debounce = true
		end
	end
end)
end
8 Likes