Auto farm esp  and cfg
Key Required Patched

Auto farm esp and cfg

[UPD] THE WRAITH: SURVIVALMeXaMeXa 1.9K views 18 executesUpdated Feb 25, 2026
5.0/ 5(2 votes)
20100% Positive
Lua Script•2325 lines (81324 chars)
-- ==================== ОПТИМИЗИРОВАННЫЙ СКРИПТ v2.3 ====================
-- Версия с минимальным потреблением FPS
-- Исправлено: Функция выгрузки, сохранение/загрузка настроек
-- Добавлено: Авто-кликер (без мыши), Анти-афк
-- Удалено: Стелс-режим

-- ==================== СЕРВИСЫ ====================
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local player = game:GetService("Players").LocalPlayer
local StarterGui = game:GetService("StarterGui")
local workspace = game:GetService("Workspace")
local Players = game:GetService("Players")
local CoreGui = game:GetService("CoreGui")
local VirtualUser = game:GetService("VirtualUser")
local VirtualInputManager = game:GetService("VirtualInputManager")

-- ==================== ЗАЩИТА ОТ ПОВТОРНОЙ ЗАГРУЗКИ ====================
if _G.UnifiedScriptLoaded then
    pcall(function()
        local oldGui = CoreGui:FindFirstChild("By MeXa")
        if oldGui then oldGui:Destroy() end
        
        oldGui = CoreGui:FindFirstChild("CurrentTimeGUI")
        if oldGui then oldGui:Destroy() end
        
        _G.UnifiedScriptLoaded = nil
    end)
end

_G.UnifiedScriptLoaded = true

-- ==================== СОХРАНЯЕМ ОРИГИНАЛЬНЫЕ ФУНКЦИИ ====================
local oldWarn = warn
local oldPrint = print
local mt = nil
local oldNamecall = nil

-- ==================== ПОДАВЛЕНИЕ ОШИБОК ====================
warn = function(...)
    local msg = tostring(...)
    if not msg:find("missing method 'Unequip'") and not msg:find("ClickDetector") then
        oldWarn(...)
    end
end

print = function(...)
    local msg = tostring(...)
    if not msg:find("missing method 'Unequip'") then
        oldPrint(...)
    end
end

-- ==================== ФУНКЦИЯ УВЕДОМЛЕНИЙ ====================
local lastNotifyTime = 0
local function notify(title, text, duration)
    local currentTime = os.clock()
    if currentTime - lastNotifyTime < 1 then return end
    lastNotifyTime = currentTime
    
    pcall(function()
        StarterGui:SetCore("SendNotification", {
            Title = tostring(title),
            Text = tostring(text),
            Duration = duration or 2
        })
    end)
end

-- ==================== НАСТРОЙКИ ====================
local settings = {
    damage = {
        repeatamount = 100,
        exceptions = {"SayMessageRequest", "MeleeUpdateEvent", "NinjaBombEvent", "BulletUpdateEvent"},
        enabled = false,
        bind = "O"
    },
    farm = {
        enabled = false,
        bind = "P"
    },
    autoclicker = {
        enabled = false,
        bind = "U",
        interval = 0.05
    },
    antiafk = {
        enabled = false,
        interval = 60
    }
}

-- ==================== НАСТРОЙКИ БИНДОВ ====================
local bindSettings = {
    mainGUI = {
        bind = "L",
        enabled = true
    },
    timeGUI = {
        bind = "K",
        enabled = true
    },
    esp = {
        bind = "J",
        enabled = true
    }
}

-- ==================== НАСТРОЙКИ ESP ====================
local espSettings = {
    enabled = true,
    entities = true,
    exoticGifts = true,
    orbs = true,
    players = false,
    colors = {
        entities = Color3.new(1, 0, 0),
        exotic = Color3.new(1, 1, 0),
        orb = Color3.new(0, 1, 1),
        player = Color3.new(0, 1, 0)
    }
}

-- ==================== МЕНЕДЖЕР НАСТРОЕК ====================
local SettingsManager = {}
SettingsManager.fileName = "UnifiedScript_Settings"

function SettingsManager:save()
    local success, result = pcall(function()
        local data = {
            damage = settings.damage,
            farm = settings.farm,
            autoclicker = settings.autoclicker,
            antiafk = settings.antiafk,
            bindSettings = bindSettings,
            espSettings = espSettings
        }
        
        local json = game:GetService("HttpService"):JSONEncode(data)
        
        if writefile then
            writefile(self.fileName .. ".json", json)
            return true
        elseif syn and syn.write then
            syn.write(self.fileName .. ".json", json)
            return true
        end
        return false
    end)
    
    if success and result then
        notify("Settings", "Settings saved successfully!")
    else
        notify("Settings", "Failed to save settings", 3)
    end
end

function SettingsManager:load()
    local success, data = pcall(function()
        local content = nil
        if readfile then
            content = readfile(self.fileName .. ".json")
        elseif syn and syn.read then
            content = syn.read(self.fileName .. ".json")
        end
        
        if content then
            return game:GetService("HttpService"):JSONDecode(content)
        end
        return nil
    end)
    
    if success and data then
        if data.damage then settings.damage = data.damage end
        if data.farm then settings.farm = data.farm end
        if data.autoclicker then settings.autoclicker = data.autoclicker end
        if data.antiafk then settings.antiafk = data.antiafk end
        if data.bindSettings then bindSettings = data.bindSettings end
        if data.espSettings then espSettings = data.espSettings end
        
        notify("Settings", "Settings loaded successfully!")
        return true
    else
        return false
    end
end

-- ==================== ПЕРЕМЕННЫЕ ====================
local latestOrb = nil
local exoticCount = 0
local farmCount = 0
local farmRunning = false
local lastFarmTime = 0
local FARM_COOLDOWN = 5
local cachedItems = nil
local lastCacheUpdate = 0
local CACHE_LIFETIME = 2
local SEARCH_RADIUS = 1500
local MAX_OBJECTS_PER_CYCLE = 200

local notifiedGifts = {}
local notifiedOrbs = {}

-- ESP Variables
local espObjects = {}
local espConnections = {}
local espEnabled = true

-- Auto Clicker Variables
local autoclickerRunning = false
local attackEvents = {}

-- Anti AFK Variables
local antiafkRunning = false

-- Script state
local scriptLoaded = true
local connections = {}

-- ==================== ОЖИДАНИЕ БИНДА ====================
local waitingForBind = nil
local bindButtons = {}

-- ==================== ФУНКЦИИ ====================

-- Поиск папки с предметами
local function getItemsFolder()
    local currentTime = os.clock()
    if cachedItems and currentTime - lastCacheUpdate < CACHE_LIFETIME then
        return cachedItems
    end
    
    local success, result = pcall(function()
        local Storage = workspace:FindFirstChild("Storage")
        if Storage then
            local Map = Storage:FindFirstChild("Map")
            if Map then
                return Map:FindFirstChild("Scraps")
            end
        end
        return nil
    end)
    
    if success and result then
        cachedItems = result
    else
        cachedItems = nil
    end
    
    lastCacheUpdate = currentTime
    return cachedItems
end

-- ==================== ФУНКЦИЯ ВЫГРУЗКИ ====================
local function unloadScript()
    if not scriptLoaded then return end
    
    pcall(function()
        StarterGui:SetCore("SendNotification", {
            Title = "Script",
            Text = "Unloading script...",
            Duration = 1
        })
    end)
    
    settings.damage.enabled = false
    settings.farm.enabled = false
    settings.autoclicker.enabled = false
    settings.antiafk.enabled = false
    espEnabled = false
    
    autoclickerRunning = false
    antiafkRunning = false
    
    for obj, esp in pairs(espObjects) do
        pcall(function()
            if esp.highlight then esp.highlight:Destroy() end
            if esp.billboard then esp.billboard:Destroy() end
        end)
    end
    espObjects = {}
    
    for i, conn in ipairs(connections) do
        pcall(function() conn:Disconnect() end)
    end
    connections = {}
    
    pcall(function() 
        if screenGui and screenGui.Parent then
            screenGui:Destroy()
        end
    end)
    
    pcall(function() 
        if timeGui and timeGui.Parent then
            timeGui:Destroy()
        end
    end)
    
    pcall(function()
        for _, v in pairs(CoreGui:GetChildren()) do
            if v.Name == "By MeXa" or v.Name == "CurrentTimeGUI" or v.Name == "RepeatDialog" or v.Name == "DialogBackground" then
                v:Destroy()
            end
        end
    end)
    
    pcall(function()
        warn = oldWarn
        print = oldPrint
    end)
    
    pcall(function()
        if mt and oldNamecall then
            setreadonly(mt, false)
            mt.__namecall = oldNamecall
            setreadonly(mt, true)
        end
    end)
    
    scriptLoaded = false
    waitingForBind = nil
    _G.UnifiedScriptLoaded = nil
    
    collectgarbage()
    
    pcall(function()
        StarterGui:SetCore("SendNotification", {
            Title = "Script",
            Text = "Script unloaded successfully!",
            Duration = 2
        })
    end)
    
    oldPrint("✓ Script полностью выгружен")
end

-- ==================== ФУНКЦИИ ESP ====================

local function createHighlight(obj, color, text)
    if not obj then return nil end
    
    local adornee = obj
    if obj:IsA("Model") then
        if obj.PrimaryPart then
            adornee = obj.PrimaryPart
        else
            for _, part in ipairs(obj:GetDescendants()) do
                if part:IsA("BasePart") then
                    adornee = part
                    break
                end
            end
        end
    end
    
    if not adornee or not adornee:IsA("BasePart") then
        return nil
    end
    
    local billboard = Instance.new("BillboardGui")
    billboard.Parent = adornee
    billboard.Adornee = adornee
    billboard.Size = UDim2.new(0, 100, 0, 30)
    billboard.StudsOffset = Vector3.new(0, 3, 0)
    billboard.AlwaysOnTop = true
    
    local textLabel = Instance.new("TextLabel")
    textLabel.Parent = billboard
    textLabel.Size = UDim2.new(1, 0, 1, 0)
    textLabel.BackgroundTransparency = 1
    textLabel.Text = text or obj.Name
    textLabel.TextColor3 = color or Color3.new(1, 1, 1)
    textLabel.TextSize = 14
    textLabel.Font = Enum.Font.SourceSansBold
    textLabel.TextStrokeTransparency = 0.5
    textLabel.TextStrokeColor3 = Color3.new(0, 0, 0)
    
    local highlight = Instance.new("Highlight")
    highlight.Parent = adornee
    highlight.Adornee = adornee
    highlight.FillColor = color or Color3.new(1, 0, 0)
    highlight.FillTransparency = 0.5
    highlight.OutlineColor = Color3.new(1, 1, 1)
    highlight.OutlineTransparency = 0
    highlight.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
    
    return {
        highlight = highlight,
        billboard = billboard,
        obj = obj
    }
end

local function removeESP(obj)
    if espObjects[obj] then
        pcall(function()
            if espObjects[obj].highlight then
                espObjects[obj].highlight:Destroy()
            end
            if espObjects[obj].billboard then
                espObjects[obj].billboard:Destroy()
            end
        end)
        espObjects[obj] = nil
    end
end

local function updateESP()
    if not espEnabled or not scriptLoaded then
        for obj, _ in pairs(espObjects) do
            removeESP(obj)
        end
        return
    end
    
    local currentObjects = {}
    
    if espSettings.entities then
        local entitiesFolder = workspace:FindFirstChild("Entities")
        if entitiesFolder then
            local success, children = pcall(function() return entitiesFolder:GetChildren() end)
            if success and children then
                for _, v in ipairs(children) do
                    if v and not currentObjects[v] then
                        currentObjects[v] = true
                        if not espObjects[v] then
                            local esp = createHighlight(v, espSettings.colors.entities, "ENTITY: " .. v.Name)
                            if esp then
                                espObjects[v] = esp
                            end
                        end
                    end
                end
            end
        end
    end
    
    if espSettings.exoticGifts then
        local items = getItemsFolder()
        if items then
            local success, children = pcall(function() return items:GetChildren() end)
            if success and children then
                for _, v in ipairs(children) do
                    if v and v.Name == "Exotic Gift" and not currentObjects[v] then
                        currentObjects[v] = true
                        if not espObjects[v] then
                            local esp = createHighlight(v, espSettings.colors.exotic, "⭐ EXOTIC GIFT")
                            if esp then
                                espObjects[v] = esp
                            end
                        end
                    end
                end
            end
        end
    end
    
    if espSettings.orbs then
        local items = getItemsFolder()
        if items then
            local success, children = pcall(function() return items:GetChildren() end)
            if success and children then
                for _, v in ipairs(children) do
                    if v and v.Name and string.find(string.lower(v.Name), "orb") and not currentObjects[v] then
                        currentObjects[v] = true
                        if not espObjects[v] then
                            local esp = createHighlight(v, espSettings.colors.orb, "🌀 " .. v.Name)
                            if esp then
                                espObjects[v] = esp
                            end
                        end
                    end
                end
            end
        end
    end
    
    if espSettings.players then
        for _, plr in ipairs(Players:GetPlayers()) do
            if plr ~= player and plr.Character then
                local char = plr.Character
                if char and not currentObjects[char] then
                    currentObjects[char] = true
                    if not espObjects[char] then
                        local esp = createHighlight(char, espSettings.colors.player, "👤 " .. plr.Name)
                        if esp then
                            espObjects[char] = esp
                        end
                    end
                end
            end
        end
    end
    
    for obj, esp in pairs(espObjects) do
        if not currentObjects[obj] or not obj.Parent then
            removeESP(obj)
        end
    end
end

local function toggleESP()
    espEnabled = not espEnabled
    if not espEnabled then
        for obj, _ in pairs(espObjects) do
            removeESP(obj)
        end
    end
    notify("ESP", "ESP: " .. (espEnabled and "ON" or "OFF"))
    if espToggleButton then
        espToggleButton.Text = "ESP: " .. (espEnabled and "ON" or "OFF")
        espToggleButton.BackgroundColor3 = espEnabled and Color3.new(0, 0.5, 0) or Color3.new(0.5, 0, 0)
    end
end

-- ==================== АВТО-КЛИКЕР ====================

-- Поиск доступных событий атаки
local function findAttackEvents()
    attackEvents = {}
    
    local possibleEvents = {
        "MeleeUpdateEvent",
        "NinjaBombEvent",
        "AttackEvent",
        "ClickEvent",
        "SwordEvent",
        "DamageEvent"
    }
    
    for _, eventName in ipairs(possibleEvents) do
        local event = ReplicatedStorage:FindFirstChild(eventName)
        if event and (event:IsA("RemoteEvent") or event:IsA("RemoteFunction")) then
            table.insert(attackEvents, event)
        end
    end
    
    -- Поиск по всем папкам в ReplicatedStorage
    for _, folder in ipairs(ReplicatedStorage:GetChildren()) do
        if folder:IsA("Folder") then
            for _, event in ipairs(folder:GetChildren()) do
                if (event:IsA("RemoteEvent") or event:IsA("RemoteFunction")) and 
                   (string.find(event.Name:lower(), "attack") or 
                    string.find(event.Name:lower(), "melee") or 
                    string.find(event.Name:lower(), "hit") or
                    string.find(event.Name:lower(), "damage")) then
                    table.insert(attackEvents, event)
                end
            end
        end
    end
    
    return #attackEvents > 0
end

-- Функция атаки
local function performAttack()
    if not settings.autoclicker.enabled or not scriptLoaded then return end
    
    local character = player.Character
    if not character then return end
    
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if not humanoid or humanoid.Health <= 0 then return end
    
    -- Используем найденные события
    for _, event in ipairs(attackEvents) do
        pcall(function()
            if event:IsA("RemoteEvent") then
                event:FireServer()
            elseif event:IsA("RemoteFunction") then
                event:InvokeServer()
            end
        end)
    end
    
    -- Альтернативный метод: эмуляция клика через ClickDetector
    if #attackEvents == 0 then
        local mouse = player:GetMouse()
        local target = mouse.Target
        if target then
            local clickDetector = target:FindFirstChildOfClass("ClickDetector")
            if clickDetector then
                pcall(function()
                    clickDetector:FireServer()
                end)
            end
        end
    end
end

-- Запуск авто-кликера
local function startAutoclicker()
    if autoclickerRunning then return end
    autoclickerRunning = true
    
    findAttackEvents()
    
    task.spawn(function()
        while autoclickerRunning and scriptLoaded and settings.autoclicker.enabled do
            local success, err = pcall(performAttack)
            if not success then
                oldPrint("Auto-clicker error: " .. tostring(err))
            end
            task.wait(settings.autoclicker.interval)
        end
        autoclickerRunning = false
    end)
end

-- Остановка авто-кликера
local function stopAutoclicker()
    autoclickerRunning = false
end

-- Переключение авто-кликера
local function toggleAutoclicker()
    settings.autoclicker.enabled = not settings.autoclicker.enabled
    
    if settings.autoclicker.enabled then
        startAutoclicker()
        notify("Auto-Clicker", "ON (Interval: " .. settings.autoclicker.interval .. "s)")
    else
        stopAutoclicker()
        notify("Auto-Clicker", "OFF")
    end
    
    if autoclickerToggleButton then
        autoclickerToggleButton.Text = settings.autoclicker.enabled and "DISABLE" or "ENABLE"
        autoclickerToggleButton.BackgroundColor3 = settings.autoclicker.enabled and Color3.new(0, 0.5, 0) or Color3.new(0.5, 0, 0)
    end
    
    if autoclickerStatusLabel then
        autoclickerStatusLabel.Text = "Status: " .. (settings.autoclicker.enabled and "ON" or "OFF")
        autoclickerStatusLabel.TextColor3 = settings.autoclicker.enabled and Color3.new(0, 1, 0) or Color3.new(1, 0, 0)
    end
end

-- ==================== АНТИ-АФК ====================

local function performAntiAFK()
    if not settings.antiafk.enabled or not scriptLoaded then return end
    
    pcall(function()
        -- Метод 1: Движение мыши
        VirtualUser:Move(Vector2.new(100, 0), Vector2.new(1000, 1000))
        task.wait(0.1)
        
        -- Метод 2: Нажатие кнопки
        VirtualInputManager:SendKeyEvent(true, Enum.KeyCode.Unknown, false, game)
        task.wait(0.1)
        
        -- Метод 3: Отправка пустого события
        local jumpEvent = ReplicatedStorage:FindFirstChild("JumpEvent")
        if jumpEvent then
            jumpEvent:FireServer()
        end
    end)
end

-- Запуск анти-афк
local function startAntiAFK()
    if antiafkRunning then return end
    antiafkRunning = true
    
    task.spawn(function()
        while antiafkRunning and scriptLoaded and settings.antiafk.enabled do
            task.wait(settings.antiafk.interval)
            if antiafkRunning and scriptLoaded and settings.antiafk.enabled then
                local success, err = pcall(performAntiAFK)
                if not success then
                    oldPrint("Anti-AFK error: " .. tostring(err))
                end
            end
        end
        antiafkRunning = false
    end)
end

-- Остановка анти-афк
local function stopAntiAFK()
    antiafkRunning = false
end

-- Переключение анти-афк
local function toggleAntiAFK()
    settings.antiafk.enabled = not settings.antiafk.enabled
    
    if settings.antiafk.enabled then
        startAntiAFK()
        notify("Anti-AFK", "ON (Interval: " .. settings.antiafk.interval .. "s)")
    else
        stopAntiAFK()
        notify("Anti-AFK", "OFF")
    end
    
    if antiafkToggleButton then
        antiafkToggleButton.Text = settings.antiafk.enabled and "DISABLE" or "ENABLE"
        antiafkToggleButton.BackgroundColor3 = settings.antiafk.enabled and Color3.new(0, 0.5, 0) or Color3.new(0.5, 0, 0)
    end
    
    if antiafkStatusLabel then
        antiafkStatusLabel.Text = "Status: " .. (settings.antiafk.enabled and "ON" or "OFF")
        antiafkStatusLabel.TextColor3 = settings.antiafk.enabled and Color3.new(0, 1, 0) or Color3.new(1, 0, 0)
    end
end

-- ==================== ОБНОВЛЕНИЕ GUI ====================

local function updateItemsCounts()
    local counts = { exotic = 0 }
    local items = getItemsFolder()
    if items then
        local success, children = pcall(function() return items:GetChildren() end)
        if success and children then
            for _, v in ipairs(children) do
                if v and v.Name == "Exotic Gift" then
                    counts.exotic = counts.exotic + 1
                end
            end
        end
    end
    exoticCount = counts.exotic
    if exoticLabel then
        exoticLabel.Text = "Exotic Gift: " .. exoticCount
    end
end

local function updateEntitiesList()
    if not entitiesListFrame then return end
    
    for _, child in ipairs(entitiesListFrame:GetChildren()) do
        if child:IsA("TextLabel") then
            child:Destroy()
        end
    end
    
    local entitiesFolder = workspace:FindFirstChild("Entities")
    if not entitiesFolder then
        local noEntitiesLabel = Instance.new("TextLabel")
        noEntitiesLabel.Parent = entitiesListFrame
        noEntitiesLabel.Size = UDim2.new(1, -5, 0, 20)
        noEntitiesLabel.BackgroundTransparency = 1
        noEntitiesLabel.Text = "No Entities folder found"
        noEntitiesLabel.TextColor3 = Color3.new(1, 0, 0)
        noEntitiesLabel.TextSize = 12
        noEntitiesLabel.Font = Enum.Font.SourceSans
        noEntitiesLabel.TextXAlignment = Enum.TextXAlignment.Left
        return
    end
    
    local entityCount = 0
    local success, children = pcall(function() return entitiesFolder:GetChildren() end)
    
    if success and children then
        for _, v in ipairs(children) do
            if v then
                entityCount = entityCount + 1
                local entityLabel = Instance.new("TextLabel")
                entityLabel.Parent = entitiesListFrame
                entityLabel.Size = UDim2.new(1, -5, 0, 20)
                entityLabel.BackgroundTransparency = 1
                entityLabel.Text = "• " .. v.Name
                entityLabel.TextColor3 = Color3.new(1, 1, 0)
                entityLabel.TextSize = 12
                entityLabel.Font = Enum.Font.SourceSans
                entityLabel.TextXAlignment = Enum.TextXAlignment.Left
            end
        end
    end
    
    entitiesListFrame.CanvasSize = UDim2.new(0, 0, 0, entityCount * 22)
end

local function detectObjects()
    if not scriptLoaded then return end
    
    updateItemsCounts()
    updateEntitiesList()
    
    if espEnabled then
        updateESP()
    end
    
    local items = getItemsFolder()
    if items then
        local success, children = pcall(function() return items:GetChildren() end)
        if success and children then
            for _, v in ipairs(children) do
                if v and v.Name and string.find(string.lower(v.Name), "orb") and v ~= latestOrb then
                    latestOrb = v
                    if orbLabel then
                        orbLabel.Text = "Last Orb: " .. v.Name
                    end
                    notify("Orb", v.Name .. " appeared!")
                end
            end
        end
    end
end

-- ==================== ЗАХВАТ БИНДОВ ====================

local function startBindCapture(button, target)
    button.Text = "..."
    waitingForBind = {button = button, target = target}
end

local function updateBindButtons()
    if damageBindButton then damageBindButton.Text = settings.damage.bind end
    if farmBindButton then farmBindButton.Text = settings.farm.bind end
    if autoclickerBindButton then autoclickerBindButton.Text = settings.autoclicker.bind end
    if mainGUIBindButton then mainGUIBindButton.Text = bindSettings.mainGUI.bind end
    if timeGUIBindButton then timeGUIBindButton.Text = bindSettings.timeGUI.bind end
    if espBindButton then espBindButton.Text = bindSettings.esp.bind end
end

-- ==================== СОЗДАНИЕ GUI ====================

local function createOptimizedGUI()
    local screenGui = Instance.new("ScreenGui")
    screenGui.Parent = CoreGui
    screenGui.ResetOnSpawn = false
    screenGui.Name = "By MeXa"
    screenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
    screenGui.DisplayOrder = 100
    screenGui.IgnoreGuiInset = true
    
    local mainFrame = Instance.new("Frame")
    mainFrame.Parent = screenGui
    mainFrame.Size = UDim2.new(0, 600, 0, 700)
    mainFrame.Position = UDim2.new(0.5, -300, 0.5, -350)
    mainFrame.BackgroundColor3 = Color3.new(0.1, 0.1, 0.1)
    mainFrame.BackgroundTransparency = 0.1
    mainFrame.BorderSizePixel = 0
    mainFrame.Active = true
    mainFrame.Draggable = true
    mainFrame.Visible = true
    mainFrame.ClipsDescendants = true
    
    local titleLabel = Instance.new("TextLabel")
    titleLabel.Parent = mainFrame
    titleLabel.Size = UDim2.new(1, 0, 0, 25)
    titleLabel.Position = UDim2.new(0, 0, 0, 0)
    titleLabel.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    titleLabel.Text = "Unified Script v2.2 (All binds can be changed)"
    titleLabel.TextColor3 = Color3.new(1, 1, 1)
    titleLabel.TextSize = 14
    titleLabel.Font = Enum.Font.SourceSans
    
    local tabButtonsFrame = Instance.new("Frame")
    tabButtonsFrame.Parent = mainFrame
    tabButtonsFrame.Size = UDim2.new(1, 0, 0, 25)
    tabButtonsFrame.Position = UDim2.new(0, 0, 0, 25)
    tabButtonsFrame.BackgroundColor3 = Color3.new(0.15, 0.15, 0.15)
    tabButtonsFrame.BorderSizePixel = 0
    
    local damageTabButton = Instance.new("TextButton")
    damageTabButton.Parent = tabButtonsFrame
    damageTabButton.Size = UDim2.new(0.166, -1, 1, 0)
    damageTabButton.Position = UDim2.new(0, 0, 0, 0)
    damageTabButton.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
    damageTabButton.Text = "DAMAGE"
    damageTabButton.TextColor3 = Color3.new(1, 1, 1)
    damageTabButton.TextSize = 13
    damageTabButton.Font = Enum.Font.SourceSans
    damageTabButton.BorderSizePixel = 0
    damageTabButton.AutoButtonColor = false
    
    local farmTabButton = Instance.new("TextButton")
    farmTabButton.Parent = tabButtonsFrame
    farmTabButton.Size = UDim2.new(0.166, -1, 1, 0)
    farmTabButton.Position = UDim2.new(0.166, 1, 0, 0)
    farmTabButton.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    farmTabButton.Text = "FARM"
    farmTabButton.TextColor3 = Color3.new(1, 1, 1)
    farmTabButton.TextSize = 13
    farmTabButton.Font = Enum.Font.SourceSans
    farmTabButton.BorderSizePixel = 0
    farmTabButton.AutoButtonColor = false
    
    local espTabButton = Instance.new("TextButton")
    espTabButton.Parent = tabButtonsFrame
    espTabButton.Size = UDim2.new(0.166, -1, 1, 0)
    espTabButton.Position = UDim2.new(0.332, 2, 0, 0)
    espTabButton.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    espTabButton.Text = "ESP"
    espTabButton.TextColor3 = Color3.new(1, 1, 1)
    espTabButton.TextSize = 13
    espTabButton.Font = Enum.Font.SourceSans
    espTabButton.BorderSizePixel = 0
    espTabButton.AutoButtonColor = false
    
    local bindsTabButton = Instance.new("TextButton")
    bindsTabButton.Parent = tabButtonsFrame
    bindsTabButton.Size = UDim2.new(0.166, -1, 1, 0)
    bindsTabButton.Position = UDim2.new(0.498, 3, 0, 0)
    bindsTabButton.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    bindsTabButton.Text = "BINDS"
    bindsTabButton.TextColor3 = Color3.new(1, 1, 1)
    bindsTabButton.TextSize = 13
    bindsTabButton.Font = Enum.Font.SourceSans
    bindsTabButton.BorderSizePixel = 0
    bindsTabButton.AutoButtonColor = false
    
    local miscTabButton = Instance.new("TextButton")
    miscTabButton.Parent = tabButtonsFrame
    miscTabButton.Size = UDim2.new(0.166, -1, 1, 0)
    miscTabButton.Position = UDim2.new(0.664, 4, 0, 0)
    miscTabButton.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    miscTabButton.Text = "MISC"
    miscTabButton.TextColor3 = Color3.new(1, 1, 1)
    miscTabButton.TextSize = 13
    miscTabButton.Font = Enum.Font.SourceSans
    miscTabButton.BorderSizePixel = 0
    miscTabButton.AutoButtonColor = false
    
    local extraTabButton = Instance.new("TextButton")
    extraTabButton.Parent = tabButtonsFrame
    extraTabButton.Size = UDim2.new(0.166, -1, 1, 0)
    extraTabButton.Position = UDim2.new(0.83, 5, 0, 0)
    extraTabButton.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    extraTabButton.Text = "EXTRA"
    extraTabButton.TextColor3 = Color3.new(1, 1, 1)
    extraTabButton.TextSize = 13
    extraTabButton.Font = Enum.Font.SourceSans
    extraTabButton.BorderSizePixel = 0
    extraTabButton.AutoButtonColor = false
    
    local contentFrame = Instance.new("Frame")
    contentFrame.Parent = mainFrame
    contentFrame.Size = UDim2.new(1, -20, 1, -80)
    contentFrame.Position = UDim2.new(0, 10, 0, 60)
    contentFrame.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    contentFrame.BackgroundTransparency = 0.3
    contentFrame.BorderSizePixel = 0
    contentFrame.ClipsDescendants = true
    
    return screenGui, mainFrame, contentFrame, damageTabButton, farmTabButton, espTabButton, bindsTabButton, miscTabButton, extraTabButton
end

local function createTimeGUI()
    local timeGui = Instance.new("ScreenGui")
    timeGui.Parent = CoreGui
    timeGui.ResetOnSpawn = false
    timeGui.Name = "CurrentTimeGUI"
    timeGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
    timeGui.DisplayOrder = 200
    
    local timeFrame = Instance.new("Frame")
    timeFrame.Parent = timeGui
    timeFrame.Size = UDim2.new(0, 250, 0, 100)
    timeFrame.Position = UDim2.new(0.02, 0, 0.5, -50)
    timeFrame.BackgroundColor3 = Color3.new(0, 0, 0)
    timeFrame.BackgroundTransparency = 0.2
    timeFrame.BorderSizePixel = 2
    timeFrame.BorderColor3 = Color3.new(1, 1, 0)
    timeFrame.Active = true
    timeFrame.Draggable = true
    timeFrame.Visible = true
    
    local titleLabel = Instance.new("TextLabel")
    titleLabel.Parent = timeFrame
    titleLabel.Size = UDim2.new(1, 0, 0, 25)
    titleLabel.Position = UDim2.new(0, 0, 0, 0)
    titleLabel.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    titleLabel.Text = "CURRENT TIME (Bind: " .. bindSettings.timeGUI.bind .. ")"
    titleLabel.TextColor3 = Color3.new(1, 1, 0)
    titleLabel.TextSize = 13
    titleLabel.Font = Enum.Font.SourceSansBold
    
    local timeValueLabel = Instance.new("TextLabel")
    timeValueLabel.Parent = timeFrame
    timeValueLabel.Size = UDim2.new(1, 0, 1, -25)
    timeValueLabel.Position = UDim2.new(0, 0, 0, 25)
    timeValueLabel.BackgroundTransparency = 1
    timeValueLabel.Text = "Loading..."
    timeValueLabel.TextColor3 = Color3.new(0, 1, 0)
    timeValueLabel.TextSize = 36
    timeValueLabel.Font = Enum.Font.SourceSansBold
    
    return timeGui, timeFrame, timeValueLabel
end

-- Создание GUI
local screenGui, mainFrame, contentFrame, damageTabButton, farmTabButton, espTabButton, bindsTabButton, miscTabButton, extraTabButton = createOptimizedGUI()
local timeGui, timeFrame, timeValueLabel = createTimeGUI()

-- ==================== ВСПОМОГАТЕЛЬНЫЕ ФУНКЦИИ ДЛЯ GUI ====================

local function createLabel(parent, text, position, color, size)
    local label = Instance.new("TextLabel")
    label.Parent = parent
    label.Size = UDim2.new(1, -20, 0, 20)
    label.Position = position
    label.BackgroundTransparency = 1
    label.Text = text
    label.TextColor3 = color or Color3.new(1, 1, 1)
    label.TextSize = size or 12
    label.Font = Enum.Font.SourceSans
    label.TextXAlignment = Enum.TextXAlignment.Left
    return label
end

local function createButton(parent, text, position, size, color)
    local button = Instance.new("TextButton")
    button.Parent = parent
    button.Size = size or UDim2.new(0, 120, 0, 25)
    button.Position = position
    button.BackgroundColor3 = color or Color3.new(0.3, 0.3, 0.3)
    button.Text = text
    button.TextColor3 = Color3.new(1, 1, 1)
    button.TextSize = 12
    button.Font = Enum.Font.SourceSans
    button.BorderSizePixel = 0
    button.AutoButtonColor = false
    return button
end

-- ==================== ВКЛАДКА ESP ====================

local espFrame = Instance.new("Frame")
espFrame.Parent = contentFrame
espFrame.Size = UDim2.new(1, 0, 1, 0)
espFrame.BackgroundTransparency = 1
espFrame.Visible = false
espFrame.ClipsDescendants = true

-- ESP Title
local espTitle = createLabel(espFrame, "=== ESP SETTINGS ===", UDim2.new(0, 10, 0, 5), Color3.new(0, 1, 0), 16)
espTitle.Size = UDim2.new(1, -20, 0, 25)
espTitle.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
espTitle.BackgroundTransparency = 0
espTitle.TextXAlignment = Enum.TextXAlignment.Center

-- ESP Toggle
espToggleButton = createButton(espFrame, "ESP: ON", UDim2.new(0, 10, 0, 40), UDim2.new(0, 120, 0, 30), Color3.new(0, 0.5, 0))
espToggleButton.TextSize = 14

-- ESP Bind
createLabel(espFrame, "ESP Bind:", UDim2.new(0, 140, 0, 45))
espBindButton = createButton(espFrame, bindSettings.esp.bind, UDim2.new(0, 210, 0, 45), UDim2.new(0, 45, 0, 22))

-- ESP Categories
local categoriesTitle = createLabel(espFrame, "--- Categories ---", UDim2.new(0, 10, 0, 80), Color3.new(1, 1, 0), 14)

-- Entities toggle
local entitiesToggle = createButton(espFrame, "Entities: ON", UDim2.new(0, 10, 0, 105), UDim2.new(0, 150, 0, 25), Color3.new(0.7, 0, 0))

-- Exotic Gifts toggle
local exoticToggle = createButton(espFrame, "Exotic Gifts: ON", UDim2.new(0, 170, 0, 105), UDim2.new(0, 150, 0, 25), Color3.new(0.7, 0.7, 0))

-- Orbs toggle
local orbsToggle = createButton(espFrame, "Orbs: ON", UDim2.new(0, 10, 0, 135), UDim2.new(0, 150, 0, 25), Color3.new(0, 0.7, 0.7))

-- Players toggle
local playersToggle = createButton(espFrame, "Players: OFF", UDim2.new(0, 170, 0, 135), UDim2.new(0, 150, 0, 25), Color3.new(0, 0.7, 0))

-- Color preview
local colorsTitle = createLabel(espFrame, "--- Colors ---", UDim2.new(0, 10, 0, 175), Color3.new(1, 1, 0), 14)

local function createColorPreview(parent, text, color, pos)
    local frame = Instance.new("Frame")
    frame.Parent = parent
    frame.Size = UDim2.new(0, 20, 0, 20)
    frame.Position = pos
    frame.BackgroundColor3 = color
    frame.BorderSizePixel = 0
    
    local label = Instance.new("TextLabel")
    label.Parent = parent
    label.Size = UDim2.new(0, 100, 0, 20)
    label.Position = pos + UDim2.new(0, 25, 0, 0)
    label.BackgroundTransparency = 1
    label.Text = text
    label.TextColor3 = Color3.new(1, 1, 1)
    label.TextSize = 12
    label.Font = Enum.Font.SourceSans
    label.TextXAlignment = Enum.TextXAlignment.Left
end

createColorPreview(espFrame, "Entities", espSettings.colors.entities, UDim2.new(0, 10, 0, 200))
createColorPreview(espFrame, "Exotic", espSettings.colors.exotic, UDim2.new(0, 10, 0, 225))
createColorPreview(espFrame, "Orbs", espSettings.colors.orb, UDim2.new(0, 10, 0, 250))
createColorPreview(espFrame, "Players", espSettings.colors.player, UDim2.new(0, 10, 0, 275))

-- Info
local infoLabel = createLabel(espFrame, "ESP shows highlighted objects with names", UDim2.new(0, 10, 0, 310), Color3.new(1, 1, 1), 12)
infoLabel.Size = UDim2.new(1, -20, 0, 40)
infoLabel.TextWrapped = true

-- ==================== ВКЛАДКА BINDS ====================

local bindsFrame = Instance.new("Frame")
bindsFrame.Parent = contentFrame
bindsFrame.Size = UDim2.new(1, 0, 1, 0)
bindsFrame.BackgroundTransparency = 1
bindsFrame.Visible = false
bindsFrame.ClipsDescendants = true

-- Title
local bindsTitle = createLabel(bindsFrame, "=== KEY BINDINGS ===", UDim2.new(0, 10, 0, 5), Color3.new(1, 1, 0), 16)
bindsTitle.Size = UDim2.new(1, -20, 0, 25)
bindsTitle.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
bindsTitle.BackgroundTransparency = 0
bindsTitle.TextXAlignment = Enum.TextXAlignment.Center

-- Damage bind
createLabel(bindsFrame, "Damage Toggle:", UDim2.new(0, 10, 0, 40))
local damageBindButtonBinds = createButton(bindsFrame, settings.damage.bind, UDim2.new(0, 120, 0, 40), UDim2.new(0, 45, 0, 22))

-- Farm bind
createLabel(bindsFrame, "Farm Toggle:", UDim2.new(0, 10, 0, 70))
local farmBindButtonBinds = createButton(bindsFrame, settings.farm.bind, UDim2.new(0, 120, 0, 70), UDim2.new(0, 45, 0, 22))

-- Auto Clicker bind
createLabel(bindsFrame, "Auto-Clicker:", UDim2.new(0, 10, 0, 100))
local autoclickerBindButtonBinds = createButton(bindsFrame, settings.autoclicker.bind, UDim2.new(0, 120, 0, 100), UDim2.new(0, 45, 0, 22))

-- Main GUI bind
createLabel(bindsFrame, "Main GUI:", UDim2.new(0, 10, 0, 130))
mainGUIBindButton = createButton(bindsFrame, bindSettings.mainGUI.bind, UDim2.new(0, 120, 0, 130), UDim2.new(0, 45, 0, 22))

-- Time GUI bind
createLabel(bindsFrame, "Time GUI:", UDim2.new(0, 10, 0, 160))
timeGUIBindButton = createButton(bindsFrame, bindSettings.timeGUI.bind, UDim2.new(0, 120, 0, 160), UDim2.new(0, 45, 0, 22))

-- ESP bind
createLabel(bindsFrame, "ESP Toggle:", UDim2.new(0, 10, 0, 190))
local espBindButtonBinds = createButton(bindsFrame, bindSettings.esp.bind, UDim2.new(0, 120, 0, 190), UDim2.new(0, 45, 0, 22))

-- Instruction
local instructionLabel = createLabel(bindsFrame, "Click any bind button then press a key to change it", UDim2.new(0, 10, 0, 230), Color3.new(1, 1, 0), 14)
instructionLabel.Size = UDim2.new(1, -20, 0, 40)
instructionLabel.TextWrapped = true

-- ==================== ВКЛАДКА MISC ====================

local miscFrame = Instance.new("Frame")
miscFrame.Parent = contentFrame
miscFrame.Size = UDim2.new(1, 0, 1, 0)
miscFrame.BackgroundTransparency = 1
miscFrame.Visible = false
miscFrame.ClipsDescendants = true

-- Title
local miscTitle = createLabel(miscFrame, "=== MISCELLANEOUS ===", UDim2.new(0, 10, 0, 5), Color3.new(0, 1, 1), 16)
miscTitle.Size = UDim2.new(1, -20, 0, 25)
miscTitle.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
miscTitle.BackgroundTransparency = 0
miscTitle.TextXAlignment = Enum.TextXAlignment.Center

-- Script Status
local scriptStatusLabel = createLabel(miscFrame, "Script Status: RUNNING", UDim2.new(0, 10, 0, 40), Color3.new(0, 1, 0), 14)
scriptStatusLabel.Size = UDim2.new(1, -20, 0, 25)
scriptStatusLabel.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
scriptStatusLabel.BackgroundTransparency = 0
scriptStatusLabel.TextXAlignment = Enum.TextXAlignment.Center

-- SETTINGS MANAGEMENT
local settingsTitle = createLabel(miscFrame, "--- SETTINGS ---", UDim2.new(0, 10, 0, 70), Color3.new(1, 1, 0), 14)

-- Save Settings button
local saveSettingsButton = createButton(miscFrame, "💾 SAVE SETTINGS", UDim2.new(0, 10, 0, 95), UDim2.new(1, -20, 0, 30), Color3.new(0, 0.5, 0))
saveSettingsButton.TextSize = 14

-- Load Settings button
local loadSettingsButton = createButton(miscFrame, "📂 LOAD SETTINGS", UDim2.new(0, 10, 0, 130), UDim2.new(1, -20, 0, 30), Color3.new(0, 0, 0.5))
loadSettingsButton.TextSize = 14

-- Memory Usage
local memoryLabel = createLabel(miscFrame, "Memory Usage: Calculating...", UDim2.new(0, 10, 0, 175), Color3.new(1, 1, 1), 12)

-- ESP Objects Count
local espCountLabel = createLabel(miscFrame, "ESP Objects: 0", UDim2.new(0, 10, 0, 200), Color3.new(1, 1, 1), 12)

-- Separator
local separator1 = createLabel(miscFrame, "------------------------", UDim2.new(0, 10, 0, 225), Color3.new(1, 1, 1), 12)

-- UNLOAD BUTTON
local unloadWarning = createLabel(miscFrame, "WARNING: This will remove the entire script!", UDim2.new(0, 10, 0, 250), Color3.new(1, 0, 0), 14)
unloadWarning.Size = UDim2.new(1, -20, 0, 25)
unloadWarning.BackgroundColor3 = Color3.new(0.3, 0, 0)
unloadWarning.BackgroundTransparency = 0
unloadWarning.TextXAlignment = Enum.TextXAlignment.Center

local unloadButton = createButton(miscFrame, "UNLOAD SCRIPT", UDim2.new(0, 10, 0, 280), UDim2.new(1, -20, 0, 40), Color3.new(0.8, 0, 0))
unloadButton.TextSize = 16
unloadButton.TextColor3 = Color3.new(1, 1, 1)

local confirmFrame = Instance.new("Frame")
confirmFrame.Parent = miscFrame
confirmFrame.Size = UDim2.new(1, -20, 0, 60)
confirmFrame.Position = UDim2.new(0, 10, 0, 330)
confirmFrame.BackgroundColor3 = Color3.new(0.3, 0.2, 0.2)
confirmFrame.BackgroundTransparency = 0
confirmFrame.BorderSizePixel = 2
confirmFrame.BorderColor3 = Color3.new(1, 0, 0)
confirmFrame.Visible = false

local confirmLabel = createLabel(confirmFrame, "Are you sure? This cannot be undone!", UDim2.new(0, 10, 0, 5), Color3.new(1, 1, 0), 14)
confirmLabel.Size = UDim2.new(1, -20, 0, 20)

local confirmYes = createButton(confirmFrame, "YES", UDim2.new(0, 10, 0, 30), UDim2.new(0, 100, 0, 25), Color3.new(0.8, 0, 0))
local confirmNo = createButton(confirmFrame, "NO", UDim2.new(1, -110, 0, 30), UDim2.new(0, 100, 0, 25), Color3.new(0.3, 0.3, 0.3))

-- Separator
local separator2 = createLabel(miscFrame, "------------------------", UDim2.new(0, 10, 0, 400), Color3.new(1, 1, 1), 12)

-- FPS Counter
local fpsLabel = createLabel(miscFrame, "FPS: 60", UDim2.new(0, 10, 0, 425), Color3.new(1, 1, 1), 12)

-- Info
local miscInfo = createLabel(miscFrame, "v2.2 - Added Auto-Clicker (no mouse) and Anti-AFK", UDim2.new(0, 10, 0, 450), Color3.new(1, 1, 0), 12)
miscInfo.Size = UDim2.new(1, -20, 0, 40)
miscInfo.TextWrapped = true

-- ==================== ВКЛАДКА EXTRA ====================

local extraFrame = Instance.new("Frame")
extraFrame.Parent = contentFrame
extraFrame.Size = UDim2.new(1, 0, 1, 0)
extraFrame.BackgroundTransparency = 1
extraFrame.Visible = false
extraFrame.ClipsDescendants = true

-- Title
local extraTitle = createLabel(extraFrame, "=== AUTO CLICKER & ANTI-AFK ===", UDim2.new(0, 10, 0, 5), Color3.new(0, 1, 0), 16)
extraTitle.Size = UDim2.new(1, -20, 0, 25)
extraTitle.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
extraTitle.BackgroundTransparency = 0
extraTitle.TextXAlignment = Enum.TextXAlignment.Center

-- ===== AUTO CLICKER SECTION =====
local autoclickerTitle = createLabel(extraFrame, "--- AUTO CLICKER (NO MOUSE) ---", UDim2.new(0, 10, 0, 40), Color3.new(1, 1, 0), 14)

-- Status
autoclickerStatusLabel = createLabel(extraFrame, "Status: OFF", UDim2.new(0, 10, 0, 65), Color3.new(1, 0, 0), 14)
autoclickerStatusLabel.Size = UDim2.new(1, -20, 0, 20)

-- Toggle button
autoclickerToggleButton = createButton(extraFrame, "ENABLE", UDim2.new(0, 10, 0, 90), UDim2.new(0, 120, 0, 30), Color3.new(0.5, 0, 0))
autoclickerToggleButton.TextSize = 14

-- Bind button
createLabel(extraFrame, "Bind:", UDim2.new(0, 140, 0, 95))
autoclickerBindButton = createButton(extraFrame, settings.autoclicker.bind, UDim2.new(0, 180, 0, 95), UDim2.new(0, 45, 0, 22))

-- Interval settings
createLabel(extraFrame, "Current interval:", UDim2.new(0, 10, 0, 130))
local autoclickerIntervalLabel = createLabel(extraFrame, tostring(settings.autoclicker.interval) .. "s", UDim2.new(0, 120, 0, 130), Color3.new(0, 1, 0))
autoclickerIntervalLabel.TextXAlignment = Enum.TextXAlignment.Right
autoclickerIntervalLabel.Size = UDim2.new(0, 60, 0, 20)

local changeAutoclickerIntervalButton = createButton(extraFrame, "Change interval", UDim2.new(0, 190, 0, 130), UDim2.new(0, 120, 0, 22))

-- Info
local autoclickerInfo = createLabel(extraFrame, "Attacks automatically without mouse movement", UDim2.new(0, 10, 0, 165), Color3.new(0, 1, 1), 12)
autoclickerInfo.Size = UDim2.new(1, -20, 0, 20)

-- Separator
local separator3 = createLabel(extraFrame, "------------------------", UDim2.new(0, 10, 0, 195), Color3.new(1, 1, 1), 12)

-- ===== ANTI-AFK SECTION =====
local antiafkTitle = createLabel(extraFrame, "--- ANTI-AFK ---", UDim2.new(0, 10, 0, 220), Color3.new(1, 1, 0), 14)

-- Status
antiafkStatusLabel = createLabel(extraFrame, "Status: OFF", UDim2.new(0, 10, 0, 245), Color3.new(1, 0, 0), 14)
antiafkStatusLabel.Size = UDim2.new(1, -20, 0, 20)

-- Toggle button
antiafkToggleButton = createButton(extraFrame, "ENABLE", UDim2.new(0, 10, 0, 270), UDim2.new(0, 120, 0, 30), Color3.new(0.5, 0, 0))
antiafkToggleButton.TextSize = 14

-- Interval settings
createLabel(extraFrame, "Interval:", UDim2.new(0, 10, 0, 310))
local antiafkIntervalLabel = createLabel(extraFrame, tostring(settings.antiafk.interval) .. "s", UDim2.new(0, 120, 0, 310), Color3.new(0, 1, 0))
antiafkIntervalLabel.TextXAlignment = Enum.TextXAlignment.Right
antiafkIntervalLabel.Size = UDim2.new(0, 60, 0, 20)

local changeAntiafkIntervalButton = createButton(extraFrame, "Change interval", UDim2.new(0, 190, 0, 310), UDim2.new(0, 120, 0, 22))

-- Info
local antiafkInfo = createLabel(extraFrame, "Prevents being kicked for inactivity", UDim2.new(0, 10, 0, 345), Color3.new(0, 1, 1), 12)
antiafkInfo.Size = UDim2.new(1, -20, 0, 20)

-- ==================== УПРАВЛЕНИЕ ВКЛАДКАМИ ====================

local function selectTab(tab)
    damageFrame.Visible = (tab == "damage")
    farmFrame.Visible = (tab == "farm")
    espFrame.Visible = (tab == "esp")
    bindsFrame.Visible = (tab == "binds")
    miscFrame.Visible = (tab == "misc")
    extraFrame.Visible = (tab == "extra")
    
    damageTabButton.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    farmTabButton.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    espTabButton.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    bindsTabButton.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    miscTabButton.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    extraTabButton.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    
    if tab == "damage" then
        damageTabButton.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
    elseif tab == "farm" then
        farmTabButton.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
    elseif tab == "esp" then
        espTabButton.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
    elseif tab == "binds" then
        bindsTabButton.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
    elseif tab == "misc" then
        miscTabButton.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
    elseif tab == "extra" then
        extraTabButton.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
    end
end

damageTabButton.MouseButton1Click:Connect(function() selectTab("damage") end)
farmTabButton.MouseButton1Click:Connect(function() selectTab("farm") end)
espTabButton.MouseButton1Click:Connect(function() selectTab("esp") end)
bindsTabButton.MouseButton1Click:Connect(function() selectTab("binds") end)
miscTabButton.MouseButton1Click:Connect(function() selectTab("misc") end)
extraTabButton.MouseButton1Click:Connect(function() selectTab("extra") end)

-- ==================== НАСТРОЙКА БИНДОВ ====================

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed then return end
    if waitingForBind and input.KeyCode ~= Enum.KeyCode.Unknown then
        local key = input.KeyCode.Name
        waitingForBind.button.Text = key
        
        if waitingForBind.target == "farm" then
            settings.farm.bind = key
        elseif waitingForBind.target == "autoclicker" then
            settings.autoclicker.bind = key
        elseif waitingForBind.target == "mainGUI" then
            bindSettings.mainGUI.bind = key
        elseif waitingForBind.target == "timeGUI" then
            bindSettings.timeGUI.bind = key
            timeFrame.Title = "CURRENT TIME (Bind: " .. key .. ")"
        elseif waitingForBind.target == "esp" then
            bindSettings.esp.bind = key
        end
        
        waitingForBind = nil
        updateBindButtons()
    end
end)

-- Bind button connections
damageBindButton.MouseButton1Click:Connect(function() startBindCapture(damageBindButton, "damage") end)
damageBindButtonBinds.MouseButton1Click:Connect(function() startBindCapture(damageBindButtonBinds, "damage") end)

farmBindButton.MouseButton1Click:Connect(function() startBindCapture(farmBindButton, "farm") end)
farmBindButtonBinds.MouseButton1Click:Connect(function() startBindCapture(farmBindButtonBinds, "farm") end)

autoclickerBindButton.MouseButton1Click:Connect(function() startBindCapture(autoclickerBindButton, "autoclicker") end)
autoclickerBindButtonBinds.MouseButton1Click:Connect(function() startBindCapture(autoclickerBindButtonBinds, "autoclicker") end)

mainGUIBindButton.MouseButton1Click:Connect(function() startBindCapture(mainGUIBindButton, "mainGUI") end)

timeGUIBindButton.MouseButton1Click:Connect(function() startBindCapture(timeGUIBindButton, "timeGUI") end)

espBindButton.MouseButton1Click:Connect(function() startBindCapture(espBindButton, "esp") end)
espBindButtonBinds.MouseButton1Click:Connect(function() startBindCapture(espBindButtonBinds, "esp") end)

-- ==================== ОБРАБОТЧИК ВЫГРУЗКИ ====================

local confirmVisible = false

unloadButton.MouseButton1Click:Connect(function()
    confirmVisible = not confirmVisible
    confirmFrame.Visible = confirmVisible
end)

confirmYes.MouseButton1Click:Connect(function()
    unloadScript()
end)

confirmNo.MouseButton1Click:Connect(function()
    confirmFrame.Visible = false
    confirmVisible = false
end)

-- ==================== ОБНОВЛЕНИЕ UI ====================

local function updateDamageUI()
    if settings.damage.enabled then
        damageStatusLabel.Text = "STATUS: ON"
        damageStatusLabel.TextColor3 = Color3.new(0, 1, 0)
        damageToggleButton.Text = "DISABLE"
        damageToggleButton.BackgroundColor3 = Color3.new(0, 0.5, 0)
    else
        damageStatusLabel.Text = "STATUS: OFF"
        damageStatusLabel.TextColor3 = Color3.new(1, 0, 0)
        damageToggleButton.Text = "ENABLE"
        damageToggleButton.BackgroundColor3 = Color3.new(0.5, 0, 0)
    end
    repeatValueLabel.Text = tostring(settings.damage.repeatamount)
    damageBindButton.Text = settings.damage.bind
    damageBindButtonBinds.Text = settings.damage.bind
end

local function updateFarmUI()
    if settings.farm.enabled then
        farmStatusLabel.Text = "STATUS: ON"
        farmStatusLabel.TextColor3 = Color3.new(0, 1, 0)
        farmToggleButton.Text = "DISABLE"
        farmToggleButton.BackgroundColor3 = Color3.new(0, 0.5, 0)
    else
        farmStatusLabel.Text = "STATUS: OFF"
        farmStatusLabel.TextColor3 = Color3.new(1, 0, 0)
        farmToggleButton.Text = "ENABLE"
        farmToggleButton.BackgroundColor3 = Color3.new(0.5, 0, 0)
    end
    farmBindButton.Text = settings.farm.bind
    farmBindButtonBinds.Text = settings.farm.bind
end

local function updateAutoclickerUI()
    if settings.autoclicker.enabled then
        autoclickerStatusLabel.Text = "Status: ON"
        autoclickerStatusLabel.TextColor3 = Color3.new(0, 1, 0)
        autoclickerToggleButton.Text = "DISABLE"
        autoclickerToggleButton.BackgroundColor3 = Color3.new(0, 0.5, 0)
    else
        autoclickerStatusLabel.Text = "Status: OFF"
        autoclickerStatusLabel.TextColor3 = Color3.new(1, 0, 0)
        autoclickerToggleButton.Text = "ENABLE"
        autoclickerToggleButton.BackgroundColor3 = Color3.new(0.5, 0, 0)
    end
    autoclickerBindButton.Text = settings.autoclicker.bind
    autoclickerBindButtonBinds.Text = settings.autoclicker.bind
    autoclickerIntervalLabel.Text = tostring(settings.autoclicker.interval) .. "s"
end

local function updateAntiafkUI()
    if settings.antiafk.enabled then
        antiafkStatusLabel.Text = "Status: ON"
        antiafkStatusLabel.TextColor3 = Color3.new(0, 1, 0)
        antiafkToggleButton.Text = "DISABLE"
        antiafkToggleButton.BackgroundColor3 = Color3.new(0, 0.5, 0)
    else
        antiafkStatusLabel.Text = "Status: OFF"
        antiafkStatusLabel.TextColor3 = Color3.new(1, 0, 0)
        antiafkToggleButton.Text = "ENABLE"
        antiafkToggleButton.BackgroundColor3 = Color3.new(0.5, 0, 0)
    end
    antiafkIntervalLabel.Text = tostring(settings.antiafk.interval) .. "s"
end

-- Update MISC info
local function updateMiscInfo()
    if not scriptLoaded then return end
    
    local espCount = 0
    for _ in pairs(espObjects) do
        espCount = espCount + 1
    end
    espCountLabel.Text = "ESP Objects: " .. espCount
    
    local fps = math.floor(1 / RunService.Heartbeat:Wait())
    fpsLabel.Text = "FPS: " .. math.min(fps, 60)
    
    local mem = collectgarbage("count")
    memoryLabel.Text = string.format("Memory Usage: %.2f KB", mem)
end

-- ==================== ОБРАБОТЧИКИ КНОПОК ====================

damageToggleButton.MouseButton1Click:Connect(function()
    settings.damage.enabled = not settings.damage.enabled
    updateDamageUI()
end)

farmToggleButton.MouseButton1Click:Connect(function()
    settings.farm.enabled = not settings.farm.enabled
    updateFarmUI()
end)

espToggleButton.MouseButton1Click:Connect(function()
    toggleESP()
end)

autoclickerToggleButton.MouseButton1Click:Connect(function()
    toggleAutoclicker()
end)

antiafkToggleButton.MouseButton1Click:Connect(function()
    toggleAntiAFK()
end)

entitiesToggle.MouseButton1Click:Connect(function()
    espSettings.entities = not espSettings.entities
    entitiesToggle.Text = "Entities: " .. (espSettings.entities and "ON" or "OFF")
    entitiesToggle.BackgroundColor3 = espSettings.entities and Color3.new(0.7, 0, 0) or Color3.new(0.3, 0.3, 0.3)
    updateESP()
end)

exoticToggle.MouseButton1Click:Connect(function()
    espSettings.exoticGifts = not espSettings.exoticGifts
    exoticToggle.Text = "Exotic Gifts: " .. (espSettings.exoticGifts and "ON" or "OFF")
    exoticToggle.BackgroundColor3 = espSettings.exoticGifts and Color3.new(0.7, 0.7, 0) or Color3.new(0.3, 0.3, 0.3)
    updateESP()
end)

orbsToggle.MouseButton1Click:Connect(function()
    espSettings.orbs = not espSettings.orbs
    orbsToggle.Text = "Orbs: " .. (espSettings.orbs and "ON" or "OFF")
    orbsToggle.BackgroundColor3 = espSettings.orbs and Color3.new(0, 0.7, 0.7) or Color3.new(0.3, 0.3, 0.3)
    updateESP()
end)

playersToggle.MouseButton1Click:Connect(function()
    espSettings.players = not espSettings.players
    playersToggle.Text = "Players: " .. (espSettings.players and "ON" or "OFF")
    playersToggle.BackgroundColor3 = espSettings.players and Color3.new(0, 0.7, 0) or Color3.new(0.3, 0.3, 0.3)
    updateESP()
end)

-- Settings Handlers
saveSettingsButton.MouseButton1Click:Connect(function()
    SettingsManager:save()
end)

loadSettingsButton.MouseButton1Click:Connect(function()
    if SettingsManager:load() then
        updateDamageUI()
        updateFarmUI()
        updateAutoclickerUI()
        updateAntiafkUI()
        updateBindButtons()
        updateESP()
        
        if settings.autoclicker.enabled then
            startAutoclicker()
        else
            stopAutoclicker()
        end
        
        if settings.antiafk.enabled then
            startAntiAFK()
        else
            stopAntiAFK()
        end
    end
end)

-- ==================== ДИАЛОГИ ИЗМЕНЕНИЯ ИНТЕРВАЛОВ ====================

-- Change repeat amount dialog
changeRepeatButton.MouseButton1Click:Connect(function()
    for _, v in pairs(screenGui:GetChildren()) do
        if v.Name == "RepeatDialog" then
            v:Destroy()
        end
    end
    
    local dialogFrame = Instance.new("Frame")
    dialogFrame.Name = "RepeatDialog"
    dialogFrame.Parent = screenGui
    dialogFrame.Size = UDim2.new(0, 220, 0, 130)
    dialogFrame.Position = UDim2.new(0.5, -110, 0.5, -65)
    dialogFrame.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    dialogFrame.BorderSizePixel = 0
    dialogFrame.ZIndex = 10
    dialogFrame.Active = true
    dialogFrame.Draggable = true
    
    local backgroundBlur = Instance.new("Frame")
    backgroundBlur.Parent = screenGui
    backgroundBlur.Name = "DialogBackground"
    backgroundBlur.Size = UDim2.new(1, 0, 1, 0)
    backgroundBlur.BackgroundColor3 = Color3.new(0, 0, 0)
    backgroundBlur.BackgroundTransparency = 0.5
    backgroundBlur.BorderSizePixel = 0
    backgroundBlur.ZIndex = 9
    backgroundBlur.Active = true
    
    local dialogTitle = Instance.new("TextLabel")
    dialogTitle.Parent = dialogFrame
    dialogTitle.Size = UDim2.new(1, 0, 0, 30)
    dialogTitle.Position = UDim2.new(0, 0, 0, 0)
    dialogTitle.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
    dialogTitle.Text = "Change repeat amount"
    dialogTitle.TextColor3 = Color3.new(1, 1, 1)
    dialogTitle.TextSize = 13
    dialogTitle.Font = Enum.Font.SourceSans
    dialogTitle.ZIndex = 10
    
    local instructionLabel = Instance.new("TextLabel")
    instructionLabel.Parent = dialogFrame
    instructionLabel.Size = UDim2.new(1, -20, 0, 20)
    instructionLabel.Position = UDim2.new(0, 10, 0, 35)
    instructionLabel.BackgroundTransparency = 1
    instructionLabel.Text = "Enter number from 10 to 500:"
    instructionLabel.TextColor3 = Color3.new(1, 1, 1)
    instructionLabel.TextSize = 12
    instructionLabel.Font = Enum.Font.SourceSans
    instructionLabel.TextXAlignment = Enum.TextXAlignment.Left
    instructionLabel.ZIndex = 10
    
    local textBox = Instance.new("TextBox")
    textBox.Parent = dialogFrame
    textBox.Size = UDim2.new(1, -20, 0, 25)
    textBox.Position = UDim2.new(0, 10, 0, 60)
    textBox.BackgroundColor3 = Color3.new(0.15, 0.15, 0.15)
    textBox.Text = tostring(settings.damage.repeatamount)
    textBox.TextColor3 = Color3.new(1, 1, 1)
    textBox.TextSize = 14
    textBox.Font = Enum.Font.SourceSans
    textBox.ClearTextOnFocus = true
    textBox.ZIndex = 10
    
    local confirmButton = Instance.new("TextButton")
    confirmButton.Parent = dialogFrame
    confirmButton.Size = UDim2.new(0, 80, 0, 25)
    confirmButton.Position = UDim2.new(0.5, -85, 0, 95)
    confirmButton.BackgroundColor3 = Color3.new(0, 0.5, 0)
    confirmButton.Text = "OK"
    confirmButton.TextColor3 = Color3.new(1, 1, 1)
    confirmButton.TextSize = 13
    confirmButton.Font = Enum.Font.SourceSans
    confirmButton.BorderSizePixel = 0
    confirmButton.ZIndex = 10
    
    local cancelButton = Instance.new("TextButton")
    cancelButton.Parent = dialogFrame
    cancelButton.Size = UDim2.new(0, 80, 0, 25)
    cancelButton.Position = UDim2.new(0.5, 5, 0, 95)
    cancelButton.BackgroundColor3 = Color3.new(0.5, 0, 0)
    cancelButton.Text = "Cancel"
    cancelButton.TextColor3 = Color3.new(1, 1, 1)
    cancelButton.TextSize = 13
    cancelButton.Font = Enum.Font.SourceSans
    cancelButton.BorderSizePixel = 0
    cancelButton.ZIndex = 10
    
    local function closeDialog()
        dialogFrame:Destroy()
        backgroundBlur:Destroy()
    end
    
    confirmButton.MouseButton1Click:Connect(function()
        local input = tonumber(textBox.Text)
        if input and input >= 10 and input <= 500 then
            settings.damage.repeatamount = math.floor(input)
            updateDamageUI()
            closeDialog()
        else
            textBox.Text = "Error! 10-500"
            textBox.BackgroundColor3 = Color3.new(0.5, 0, 0)
            task.wait(1)
            textBox.BackgroundColor3 = Color3.new(0.15, 0.15, 0.15)
            textBox.Text = tostring(settings.damage.repeatamount)
        end
    end)
    
    cancelButton.MouseButton1Click:Connect(closeDialog)
    
    local connection
    connection = UserInputService.InputBegan:Connect(function(input)
        if input.KeyCode == Enum.KeyCode.Escape then
            closeDialog()
            connection:Disconnect()
        end
    end)
    
    backgroundBlur.MouseButton1Click:Connect(closeDialog)
    
    textBox:CaptureFocus()
end)

-- Change autoclicker interval dialog
changeAutoclickerIntervalButton.MouseButton1Click:Connect(function()
    for _, v in pairs(screenGui:GetChildren()) do
        if v.Name == "IntervalDialog" then
            v:Destroy()
        end
    end
    
    local dialogFrame = Instance.new("Frame")
    dialogFrame.Name = "IntervalDialog"
    dialogFrame.Parent = screenGui
    dialogFrame.Size = UDim2.new(0, 220, 0, 150)
    dialogFrame.Position = UDim2.new(0.5, -110, 0.5, -75)
    dialogFrame.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    dialogFrame.BorderSizePixel = 0
    dialogFrame.ZIndex = 10
    dialogFrame.Active = true
    dialogFrame.Draggable = true
    
    local backgroundBlur = Instance.new("Frame")
    backgroundBlur.Parent = screenGui
    backgroundBlur.Name = "DialogBackground"
    backgroundBlur.Size = UDim2.new(1, 0, 1, 0)
    backgroundBlur.BackgroundColor3 = Color3.new(0, 0, 0)
    backgroundBlur.BackgroundTransparency = 0.5
    backgroundBlur.BorderSizePixel = 0
    backgroundBlur.ZIndex = 9
    backgroundBlur.Active = true
    
    local dialogTitle = Instance.new("TextLabel")
    dialogTitle.Parent = dialogFrame
    dialogTitle.Size = UDim2.new(1, 0, 0, 30)
    dialogTitle.Position = UDim2.new(0, 0, 0, 0)
    dialogTitle.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
    dialogTitle.Text = "Change auto-clicker interval"
    dialogTitle.TextColor3 = Color3.new(1, 1, 1)
    dialogTitle.TextSize = 13
    dialogTitle.Font = Enum.Font.SourceSans
    dialogTitle.ZIndex = 10
    
    local instructionLabel = Instance.new("TextLabel")
    instructionLabel.Parent = dialogFrame
    instructionLabel.Size = UDim2.new(1, -20, 0, 40)
    instructionLabel.Position = UDim2.new(0, 10, 0, 35)
    instructionLabel.BackgroundTransparency = 1
    instructionLabel.Text = "Enter interval in seconds (0.01 to 1.0):"
    instructionLabel.TextColor3 = Color3.new(1, 1, 1)
    instructionLabel.TextSize = 12
    instructionLabel.Font = Enum.Font.SourceSans
    instructionLabel.TextXAlignment = Enum.TextXAlignment.Left
    instructionLabel.TextWrapped = true
    instructionLabel.ZIndex = 10
    
    local textBox = Instance.new("TextBox")
    textBox.Parent = dialogFrame
    textBox.Size = UDim2.new(1, -20, 0, 25)
    textBox.Position = UDim2.new(0, 10, 0, 75)
    textBox.BackgroundColor3 = Color3.new(0.15, 0.15, 0.15)
    textBox.Text = tostring(settings.autoclicker.interval)
    textBox.TextColor3 = Color3.new(1, 1, 1)
    textBox.TextSize = 14
    textBox.Font = Enum.Font.SourceSans
    textBox.ClearTextOnFocus = true
    textBox.ZIndex = 10
    
    local confirmButton = Instance.new("TextButton")
    confirmButton.Parent = dialogFrame
    confirmButton.Size = UDim2.new(0, 80, 0, 25)
    confirmButton.Position = UDim2.new(0.5, -85, 0, 110)
    confirmButton.BackgroundColor3 = Color3.new(0, 0.5, 0)
    confirmButton.Text = "OK"
    confirmButton.TextColor3 = Color3.new(1, 1, 1)
    confirmButton.TextSize = 13
    confirmButton.Font = Enum.Font.SourceSans
    confirmButton.BorderSizePixel = 0
    confirmButton.ZIndex = 10
    
    local cancelButton = Instance.new("TextButton")
    cancelButton.Parent = dialogFrame
    cancelButton.Size = UDim2.new(0, 80, 0, 25)
    cancelButton.Position = UDim2.new(0.5, 5, 0, 110)
    cancelButton.BackgroundColor3 = Color3.new(0.5, 0, 0)
    cancelButton.Text = "Cancel"
    cancelButton.TextColor3 = Color3.new(1, 1, 1)
    cancelButton.TextSize = 13
    cancelButton.Font = Enum.Font.SourceSans
    cancelButton.BorderSizePixel = 0
    cancelButton.ZIndex = 10
    
    local function closeDialog()
        dialogFrame:Destroy()
        backgroundBlur:Destroy()
    end
    
    confirmButton.MouseButton1Click:Connect(function()
        local input = tonumber(textBox.Text)
        if input and input >= 0.01 and input <= 1.0 then
            settings.autoclicker.interval = input
            updateAutoclickerUI()
            
            if settings.autoclicker.enabled then
                stopAutoclicker()
                startAutoclicker()
            end
            
            closeDialog()
        else
            textBox.Text = "Error! 0.01-1.0"
            textBox.BackgroundColor3 = Color3.new(0.5, 0, 0)
            task.wait(1)
            textBox.BackgroundColor3 = Color3.new(0.15, 0.15, 0.15)
            textBox.Text = tostring(settings.autoclicker.interval)
        end
    end)
    
    cancelButton.MouseButton1Click:Connect(closeDialog)
    
    local connection
    connection = UserInputService.InputBegan:Connect(function(input)
        if input.KeyCode == Enum.KeyCode.Escape then
            closeDialog()
            connection:Disconnect()
        end
    end)
    
    backgroundBlur.MouseButton1Click:Connect(closeDialog)
    
    textBox:CaptureFocus()
end)

-- Change anti-afk interval dialog
changeAntiafkIntervalButton.MouseButton1Click:Connect(function()
    for _, v in pairs(screenGui:GetChildren()) do
        if v.Name == "AntiAfkIntervalDialog" then
            v:Destroy()
        end
    end
    
    local dialogFrame = Instance.new("Frame")
    dialogFrame.Name = "AntiAfkIntervalDialog"
    dialogFrame.Parent = screenGui
    dialogFrame.Size = UDim2.new(0, 220, 0, 150)
    dialogFrame.Position = UDim2.new(0.5, -110, 0.5, -75)
    dialogFrame.BackgroundColor3 = Color3.new(0.2, 0.2, 0.2)
    dialogFrame.BorderSizePixel = 0
    dialogFrame.ZIndex = 10
    dialogFrame.Active = true
    dialogFrame.Draggable = true
    
    local backgroundBlur = Instance.new("Frame")
    backgroundBlur.Parent = screenGui
    backgroundBlur.Name = "DialogBackground"
    backgroundBlur.Size = UDim2.new(1, 0, 1, 0)
    backgroundBlur.BackgroundColor3 = Color3.new(0, 0, 0)
    backgroundBlur.BackgroundTransparency = 0.5
    backgroundBlur.BorderSizePixel = 0
    backgroundBlur.ZIndex = 9
    backgroundBlur.Active = true
    
    local dialogTitle = Instance.new("TextLabel")
    dialogTitle.Parent = dialogFrame
    dialogTitle.Size = UDim2.new(1, 0, 0, 30)
    dialogTitle.Position = UDim2.new(0, 0, 0, 0)
    dialogTitle.BackgroundColor3 = Color3.new(0.3, 0.3, 0.3)
    dialogTitle.Text = "Change anti-AFK interval"
    dialogTitle.TextColor3 = Color3.new(1, 1, 1)
    dialogTitle.TextSize = 13
    dialogTitle.Font = Enum.Font.SourceSans
    dialogTitle.ZIndex = 10
    
    local instructionLabel = Instance.new("TextLabel")
    instructionLabel.Parent = dialogFrame
    instructionLabel.Size = UDim2.new(1, -20, 0, 40)
    instructionLabel.Position = UDim2.new(0, 10, 0, 35)
    instructionLabel.BackgroundTransparency = 1
    instructionLabel.Text = "Enter interval in seconds (10 to 300):"
    instructionLabel.TextColor3 = Color3.new(1, 1, 1)
    instructionLabel.TextSize = 12
    instructionLabel.Font = Enum.Font.SourceSans
    instructionLabel.TextXAlignment = Enum.TextXAlignment.Left
    instructionLabel.TextWrapped = true
    instructionLabel.ZIndex = 10
    
    local textBox = Instance.new("TextBox")
    textBox.Parent = dialogFrame
    textBox.Size = UDim2.new(1, -20, 0, 25)
    textBox.Position = UDim2.new(0, 10, 0, 75)
    textBox.BackgroundColor3 = Color3.new(0.15, 0.15, 0.15)
    textBox.Text = tostring(settings.antiafk.interval)
    textBox.TextColor3 = Color3.new(1, 1, 1)
    textBox.TextSize = 14
    textBox.Font = Enum.Font.SourceSans
    textBox.ClearTextOnFocus = true
    textBox.ZIndex = 10
    
    local confirmButton = Instance.new("TextButton")
    confirmButton.Parent = dialogFrame
    confirmButton.Size = UDim2.new(0, 80, 0, 25)
    confirmButton.Position = UDim2.new(0.5, -85, 0, 110)
    confirmButton.BackgroundColor3 = Color3.new(0, 0.5, 0)
    confirmButton.Text = "OK"
    confirmButton.TextColor3 = Color3.new(1, 1, 1)
    confirmButton.TextSize = 13
    confirmButton.Font = Enum.Font.SourceSans
    confirmButton.BorderSizePixel = 0
    confirmButton.ZIndex = 10
    
    local cancelButton = Instance.new("TextButton")
    cancelButton.Parent = dialogFrame
    cancelButton.Size = UDim2.new(0, 80, 0, 25)
    cancelButton.Position = UDim2.new(0.5, 5, 0, 110)
    cancelButton.BackgroundColor3 = Color3.new(0.5, 0, 0)
    cancelButton.Text = "Cancel"
    cancelButton.TextColor3 = Color3.new(1, 1, 1)
    cancelButton.TextSize = 13
    cancelButton.Font = Enum.Font.SourceSans
    cancelButton.BorderSizePixel = 0
    cancelButton.ZIndex = 10
    
    local function closeDialog()
        dialogFrame:Destroy()
        backgroundBlur:Destroy()
    end
    
    confirmButton.MouseButton1Click:Connect(function()
        local input = tonumber(textBox.Text)
        if input and input >= 10 and input <= 300 then
            settings.antiafk.interval = math.floor(input)
            updateAntiafkUI()
            
            if settings.antiafk.enabled then
                stopAntiAFK()
                startAntiAFK()
            end
            
            closeDialog()
        else
            textBox.Text = "Error! 10-300"
            textBox.BackgroundColor3 = Color3.new(0.5, 0, 0)
            task.wait(1)
            textBox.BackgroundColor3 = Color3.new(0.15, 0.15, 0.15)
            textBox.Text = tostring(settings.antiafk.interval)
        end
    end)
    
    cancelButton.MouseButton1Click:Connect(closeDialog)
    
    local connection
    connection = UserInputService.InputBegan:Connect(function(input)
        if input.KeyCode == Enum.KeyCode.Escape then
            closeDialog()
            connection:Disconnect()
        end
    end)
    
    backgroundBlur.MouseButton1Click:Connect(closeDialog)
    
    textBox:CaptureFocus()
end)

-- ==================== ОПТИМИЗИРОВАННЫЙ ДАМАГ ====================

repeat task.wait() until game:IsLoaded()

local success, mtTable = pcall(getrawmetatable, game)
if success and mtTable then
    mt = mtTable
    oldNamecall = mt.__namecall
    setreadonly(mt, false)
    
    mt.__namecall = function(self, ...)
        if not scriptLoaded or not settings.damage.enabled then 
            return oldNamecall(self, ...) 
        end
        
        local method = getnamecallmethod()
        
        if self and self.Name then
            for i = 1, #settings.damage.exceptions do
                if self.Name == settings.damage.exceptions[i] then
                    return oldNamecall(self, ...)
                end
            end
        end
        
        if method == "FireServer" or method == "InvokeServer" then
            local repeatCount = settings.damage.repeatamount
            if repeatCount > 50 then
                local batchSize = 25
                for i = 1, repeatCount, batchSize do
                    for j = 1, math.min(batchSize, repeatCount - i + 1) do
                        oldNamecall(self, ...)
                    end
                    if settings.damage.enabled and scriptLoaded then
                        task.wait()
                    else
                        break
                    end
                end
            else
                for i = 1, repeatCount do
                    oldNamecall(self, ...)
                end
            end
            return
        end
        
        return oldNamecall(self, ...)
    end
    
    setreadonly(mt, true)
end

-- ==================== ТЕКУЩЕЕ ВРЕМЯ ====================

local function updateCurrentTime()
    if not scriptLoaded then return end
    
    local valuesFolder = ReplicatedStorage:FindFirstChild("Values")
    if valuesFolder then
        local currentTimeValue = valuesFolder:FindFirstChild("currentTime")
        if currentTimeValue then
            local timeValue = currentTimeValue.Value
            
            if type(timeValue) == "number" then
                timeValueLabel.Text = string.format("%.2f", timeValue)
                
                if timeValue < 0 then
                    timeValueLabel.TextColor3 = Color3.new(1, 0, 0)
                elseif timeValue < 60 then
                    timeValueLabel.TextColor3 = Color3.new(1, 1, 0)
                else
                    timeValueLabel.TextColor3 = Color3.new(0, 1, 0)
                end
            else
                timeValueLabel.Text = tostring(timeValue)
                timeValueLabel.TextColor3 = Color3.new(1, 1, 1)
            end
            return
        end
    end
    
    timeValueLabel.Text = "N/A"
    timeValueLabel.TextColor3 = Color3.new(1, 0, 0)
end

updateCurrentTime()

RunService.RenderStepped:Connect(function()
    if scriptLoaded then
        updateCurrentTime()
        updateMiscInfo()
    end
end)

local function setupValueListener()
    local valuesFolder = ReplicatedStorage:FindFirstChild("Values")
    if valuesFolder then
        local currentTimeValue = valuesFolder:FindFirstChild("currentTime")
        if currentTimeValue and currentTimeValue:IsA("NumberValue") then
            currentTimeValue.Changed:Connect(function()
                updateCurrentTime()
            end)
        end
    end
end

setupValueListener()

task.spawn(function()
    while scriptLoaded do
        task.wait(5)
        setupValueListener()
    end
end)

-- ==================== ФУНКЦИЯ ФАРМА ====================

local function runFarmScript()
    if not settings.farm.enabled or farmRunning or not scriptLoaded then return end
    
    local currentTime = os.clock()
    if currentTime - lastFarmTime < FARM_COOLDOWN then return end
    
    farmRunning = true
    lastFarmTime = currentTime
    
    task.spawn(function()
        local success = pcall(function()
            local character = player.Character
            if not character then return end
            
            local humanoidRootPart = character:FindFirstChild("HumanoidRootPart")
            if not humanoidRootPart then return end
            
            local characterPos = humanoidRootPart.Position
            
            local clickDetectors = {}
            local touchParts = {}
            local count = 0
            
            for _, v in ipairs(workspace:GetDescendants()) do
                if not settings.farm.enabled or not scriptLoaded then break end
                if count > MAX_OBJECTS_PER_CYCLE then break end
                
                if v:IsA("BasePart") and v.Position then
                    local dist = (v.Position - characterPos).Magnitude
                    if dist > SEARCH_RADIUS then
                        continue
                    end
                end
                
                if v:IsA("ClickDetector") and v.Parent then
                    table.insert(clickDetectors, v)
                    count = count + 1
                end
                
                if v:IsA("BasePart") and v:FindFirstChildOfClass("TouchTransmitter") and v.Parent then
                    if v.CanTouch then
                        table.insert(touchParts, v)
                        count = count + 1
                    end
                end
            end
            
            for _, detector in ipairs(clickDetectors) do
                if not settings.farm.enabled or not scriptLoaded then break end
                pcall(function() 
                    detector:FireServer() 
                end)
                task.wait(0.01)
            end
            
            for _, part in ipairs(touchParts) do
                if not settings.farm.enabled or not scriptLoaded then break end
                pcall(function()
                    if part and part.Parent then
                        firetouchinterest(humanoidRootPart, part, 0)
                        task.wait(0.01)
                        firetouchinterest(humanoidRootPart, part, 1)
                    end
                end)
                task.wait(0.01)
            end
        end)
        
        if success then
            farmCount = farmCount + 1
            countLabel.Text = "Runs: " .. farmCount
        end
        
        farmRunning = false
    end)
end

-- Farm cycle
RunService.Heartbeat:Connect(function()
    if settings.farm.enabled and not farmRunning and scriptLoaded then
        runFarmScript()
    end
end)

-- ==================== ЦИКЛ ОБНАРУЖЕНИЯ ОБЪЕКТОВ ====================

task.spawn(function()
    while scriptLoaded do
        local success, err = pcall(function()
            detectObjects()
        end)
        if not success then
            oldPrint("Error in detectObjects: " .. tostring(err))
        end
        task.wait(1)
    end
end)

-- ==================== ОБРАБОТЧИКИ ДОБАВЛЕНИЯ/УДАЛЕНИЯ ОБЪЕКТОВ ====================

task.spawn(function()
    while scriptLoaded do
        local entitiesFolder = workspace:FindFirstChild("Entities")
        if entitiesFolder then
            entitiesFolder.ChildAdded:Connect(function(child)
                task.wait(0.1)
                local success, err = pcall(function()
                    if child and child.Parent and scriptLoaded then
                        detectObjects()
                    end
                end)
                if not success then
                    oldPrint("Error in ChildAdded: " .. tostring(err))
                end
            end)
            
            entitiesFolder.ChildRemoved:Connect(function(child)
                task.wait(0.1)
                local success, err = pcall(function()
                    if scriptLoaded then
                        detectObjects()
                    end
                end)
                if not success then
                    oldPrint("Error in ChildRemoved: " .. tostring(err))
                end
            end)
            break
        end
        task.wait(2)
    end
end)

task.spawn(function()
    while scriptLoaded do
        local items = getItemsFolder()
        if items then
            items.ChildAdded:Connect(function(child)
                task.wait(0.1)
                local success, err = pcall(function()
                    if child and child.Parent and scriptLoaded then
                        detectObjects()
                    end
                end)
                if not success then
                    oldPrint("Error in ChildAdded: " .. tostring(err))
                end
            end)
            
            items.ChildRemoved:Connect(function(child)
                task.wait(0.1)
                local success, err = pcall(function()
                    if scriptLoaded then
                        detectObjects()
                    end
                end)
                if not success then
                    oldPrint("Error in ChildRemoved: " .. tostring(err))
                end
            end)
            break
        end
        task.wait(2)
    end
end)

-- ==================== ОБРАБОТЧИКИ ДОБАВЛЕНИЯ/УДАЛЕНИЯ ИГРОКОВ ====================

Players.PlayerAdded:Connect(function(plr)
    if espSettings.players and scriptLoaded then
        task.wait(1)
        updateESP()
    end
end)

Players.PlayerRemoving:Connect(function(plr)
    if espSettings.players and scriptLoaded then
        updateESP()
    end
end)

-- ==================== ОЧИСТКА УВЕДОМЛЕНИЙ ====================

task.spawn(function()
    while scriptLoaded do
        task.wait(60)
        notifiedGifts = {}
        notifiedOrbs = {}
    end
end)

-- ==================== ГОРЯЧИЕ КЛАВИШИ ====================

UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if gameProcessed or not scriptLoaded then return end
    
    local key = input.KeyCode.Name
    
    -- Damage toggle
    if key == settings.damage.bind then
        settings.damage.enabled = not settings.damage.enabled
        updateDamageUI()
    end
    
    -- Farm toggle
    if key == settings.farm.bind then
        settings.farm.enabled = not settings.farm.enabled
        updateFarmUI()
    end
    
    -- Auto-clicker toggle
    if key == settings.autoclicker.bind then
        toggleAutoclicker()
    end
    
    -- Main GUI toggle
    if key == bindSettings.mainGUI.bind then
        mainFrame.Visible = not mainFrame.Visible
    end
    
    -- Time GUI toggle
    if key == bindSettings.timeGUI.bind then
        timeFrame.Visible = not timeFrame.Visible
    end
    
    -- ESP toggle
    if key == bindSettings.esp.bind then
        toggleESP()
    end
end)

-- ==================== ЗАГРУЗКА СОХРАНЁННЫХ НАСТРОЕК ====================

task.spawn(function()
    task.wait(1)
    SettingsManager:load()
    updateDamageUI()
    updateFarmUI()
    updateAutoclickerUI()
    updateAntiafkUI()
    updateBindButtons()
    updateESP()
    
    if settings.autoclicker.enabled then
        startAutoclicker()
    end
    
    if settings.antiafk.enabled then
        startAntiAFK()
    end
end)

-- ==================== ИНИЦИАЛИЗАЦИЯ ====================

updateDamageUI()
updateFarmUI()
updateAutoclickerUI()
updateAntiafkUI()
updateItemsCounts()
updateEntitiesList()
updateBindButtons()

oldPrint("✓ Optimized script v2.2 loaded!")
oldPrint("✓ Added: Auto-Clicker (no mouse movement)")
oldPrint("✓ Added: Anti-AFK system")
oldPrint("✓ Fixed: Unload function now completely removes the script")
oldPrint("✓ Added: Settings Save/Load system")
oldPrint("✓ ESP is now working with Highlight and BillboardGui")
oldPrint("✓ All binds can be changed in the BINDS tab")
oldPrint("✓ Default binds: L - Main GUI, K - Time GUI, J - ESP, U - Auto-Clicker")

Features & Information

x dmg only work ranged gun, melee=no work Gui open L Console info press F9 Custom bind xd

Community Comments (10)

MeXaMeXaFeb 25, 2026

i am add notification

MeXaMeXaFeb 27, 2026

hi i am add damage up, (damage up bugged tip always disable when buying in the store) only work ranged (mb soon add melee)

MeXaMeXaFeb 27, 2026

I would have done more than 500x, but it's already kicking in

Pot*iumUserPot*iumUserFeb 27, 2026

lol noob ezzzz

MeXaMeXaFeb 28, 2026

write what you would like

FaifnwFaifnwFeb 28, 2026

Not working bro

MeXaMeXaFeb 28, 2026

if you use Xeno, don't use Xeno *

MeXaMeXaFeb 28, 2026

don't use Solara

SavelSavelMar 17, 2026

а там телепортируется к wraith когда фарм? или он просто атакует его?

MeXaMeXaMar 19, 2026

А можно подробнее

More Scripts for [UPD] THE WRAITH: SURVIVAL