How to use the Disconnect() function without making a variable for the connection?

How to use the Disconnect() function without making a variable for the connection?

1 Like

As far as I’m aware of, you cannot use :Disconnect() without it being attached to a connection variable:

local connection = nil

connection = script.Parent.Touched:Connect(function(part)
    local humanoid = part.Parent:FindFirstChild("Humanoid")

    if humanoid then
        humanoid.Health = 0
        connection:Disconnect()
    end
end)
6 Likes

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