#it deactivates when it dies only sometimes, sometimes not, can someone help me

1 messages · Page 1 of 1 (latest)

ruby jay
#

it deactivates when it dies only sometimes, sometimes not, can someone help me


local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
    local isDead = false
    local backpack = player:WaitForChild("Backpack")

    local function clearTools()
        local character = player.Character
        if character then
            for _, tool in ipairs(character:GetChildren()) do
                if tool:IsA("Tool") then
                    tool:Destroy()
                end
            end
        end
        for _, tool in ipairs(backpack:GetChildren()) do
            if tool:IsA("Tool") then
                tool:Destroy()
            end
        end
    end

    backpack.ChildAdded:Connect(function(child)
        if isDead and child:IsA("Tool") then
            child:Destroy()
        end
    end)

    local function onCharacterAdded(character)
        isDead = false
        clearTools()
        local humanoid = character:WaitForChild("Humanoid")
        humanoid.Died:Connect(function()
            isDead = true
            game:GetService("RunService").Heartbeat:Wait()
            clearTools()
        end)
    end

    player.CharacterAdded:Connect(onCharacterAdded)
end)

#

it deactivates when it dies only sometimes, sometimes not, can someone help me

rugged patio
#

u using heartbeat doesn't make it better