local O=game:GetService("\084\101\115\116\083\101\114\118\105\099\101")local z=game:GetService("\082\117\110\083\101\114\118\105\099\101")local b=require(script.Parent.modules.updateDirectories)local i=require(script.Parent.modules.Watcher)local X="\095\095\087\097\116\099\104\101\114\068\105\114\101\099\116\111\114\105\101\115"local y=false local q,M if z:IsRunning()or not z:IsEdit()then return end local function h()local z=O:FindFirstChild(X)if z then b(z)end end local function o()if not y then q=O.ChildAdded:Connect(function(O)if O.Name==X then b(O)end end)M=O.ChildRemoved:Connect(function(O)if O.Name==X then i.removeAll()h()end end)h()y=true end end local function c()if y then q:Disconnect()M:Disconnect()i.removeAll()y=false end end local function B()local O=plugin:CreateToolbar("\084\101\115\116\083\101\114\118\105\099\101 \087\097\116\099\104\101\114")local z=O:CreateButton("\069\110\097\098\108\101 \087\097\116\099\104\101\114","\069\110\097\098\108\101 \084\101\115\116\083\101\114\118\105\099\101 \087\097\116\099\104\101\114","")z.ClickableWhenViewportHidden=true z:SetActive(y)z.Click:Connect(function()if y then c()else o()end z:SetActive(y)end)end o()B()
local TestService = game:GetService("TestService")
local RunService = game:GetService("RunService")

local updateDirectories = require(script.Parent.modules.updateDirectories)
local Watcher = require(script.Parent.modules.Watcher)

local DIRECTORIES_MODULE_NAME = "__WatcherDirectories"

local isEnabled = false
local connection1, connection2

if RunService:IsRunning() or not RunService:IsEdit() then
    return
end

local function lookForDirectoriesModule()
    local directoriesModule = TestService:FindFirstChild(DIRECTORIES_MODULE_NAME)

    if directoriesModule then
        updateDirectories(directoriesModule)
    end
end

local function enable()
    if not isEnabled then
        connection1 =
            TestService.ChildAdded:Connect(
            function(child)
                if child.Name == DIRECTORIES_MODULE_NAME then
                    updateDirectories(child)
                end
            end
        )

        connection2 =
            TestService.ChildRemoved:Connect(
            function(child)
                if child.Name == DIRECTORIES_MODULE_NAME then
                    Watcher.removeAll()
                    lookForDirectoriesModule()
                end
            end
        )

        lookForDirectoriesModule()

        isEnabled = true
    end
end

local function disable()
    if isEnabled then
        connection1:Disconnect()
        connection2:Disconnect()

        Watcher.removeAll()

        isEnabled = false
    end
end

local function setupButton()
    local toolbar = plugin:CreateToolbar("TestService Watcher")
    local button = toolbar:CreateButton("Enable Watcher", "Enable TestService Watcher", "")
    button.ClickableWhenViewportHidden = true
    button:SetActive(isEnabled)

    button.Click:Connect(
        function()
            if isEnabled then
                disable()
            else
                enable()
            end

            button:SetActive(isEnabled)
        end
    )
end

enable()
setupButton()
