local KillBrick = script.Parent
-- This one does not work
if KillBrick.Touched then
function balls (touchPart)
local humanoid = touchPart.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end
end
-- This one works as intended
KillBrick.Touched:Connect(function(touchPart)
local humanoid = touchPart.Parent:FindFirstChild("Humanoid")
if humanoid then
humanoid.Health = 0
end
end)
This is because that if statement would only run once when the script first runs. The Touched event, however, fires multiple times when something is touching the part.
It’s because you are creating the function “balls()” inside of a touched event, and never calling/firing the function.
You can always use the function method if you would like, but what’s preferable is the 2nd method, as it’s easier to access and a function is not needed for any of them.