Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I disconnect a .died event inside of a function?

Asked by 3 years ago

I've been working on a dueling arena for a bit and I've encountered a bit of an issue, a player queues, gets put into a duel (this function runs), after they complete their duel, I believe the .died event still fires so if at any point they die, their old duel partner will get respawned, aka the more duels they do the more .died events they're connected to.

function SETUP_DUEL(PLR1, PLR2)

    local ARENA
    for i,v in pairs (workspace.Arenas:GetChildren()) do
        if v:FindFirstChild("Occupied").Value == false then
            ARENA = v
        end
    end


    PLR1.Character.Died:Connect(function()
        --Code inside of here runs even after the player's done dueling.
    end)

end

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

Attach the event to a variable

local connection
connection = plr1.Character.Humanoid.Died:Connect(function()
    --do stuff
connection:Disconnect()
end)
Ad

Answer this question