Pastefi mark
Untitled
/d9bb8023
Paste view
NONE PUBLIC 42 views
d9bb8023
2026-02-25 21:48:06
if not game:IsLoaded() then game.Loaded:Wait() end

-- Защита от ошибок Disconnect
local function fixDisconnect()
    -- Сохраняем оригинальные методы
    local backup = {}
    
    -- Защищаем Connection:Disconnect()
    backup.Disconnect = getrenv().Disconnect or nil
    
    getrenv().Disconnect = function(self, ...)
        if self == nil then
            return nil
        end
        if typeof(self) ~= "RBXScriptConnection" then
            return nil
        end
        return backup.Disconnect and backup.Disconnect(self, ...)
    end
end

-- Вызываем защиту
pcall(fixDisconnect)

-- ЗВУК ДЛЯ ВСЕХ КНОПОК (С КЭШИРОВАНИЕМ)
local cachedSound = nil

local function playButtonSound()
    -- Пробуем воспроизвести кэшированный звук
    if cachedSound then
        local success = pcall(function()
            cachedSound:Stop()
            cachedSound.TimePosition = 0
            cachedSound:Play()
        end)
        
        if success then
            return
        else
            cachedSound = nil
        end
    end
    
    -- Создаем новый звук
    local success, sound = pcall(function()
        local sound = Instance.new("Sound")
        sound.SoundId = "rbxassetid://17161216230"
        sound.Volume = 1.8
        sound.Looped = false
        
        -- Пробуем разные родители
        local parent = game:GetService("SoundService")
        if not parent then
            parent = workspace
        end
        
        sound.Parent = parent
        sound:Play()
        return sound
    end)
    
    if success and sound then
        cachedSound = sound
        
        -- Автоматическая очистка если звук закончил играть
        if sound.Loaded then
            sound.Ended:Once(function()
                cachedSound = nil
            end)
        end
        
        -- Резервная очистка через 2 секунды
        task.delay(2, function()
            if cachedSound == sound then
                cachedSound = nil
            end
        end)
    end
end

-- Службы
local Services = {
    Players = game:GetService("Players"),
    UserInputService = game:GetService("UserInputService"),
    TeleportService = game:GetService("TeleportService"),
    HttpService = game:GetService("HttpService"),
    VirtualUser = game:GetService("VirtualUser"),
    SoundService = game:GetService("SoundService"),
    TweenService = game:GetService("TweenService"),
    Workspace = game:GetService("Workspace"),
    RunService = game:GetService("RunService"),
    ReplicatedStorage = game:GetService("ReplicatedStorage"),
    CollectionService = game:GetService("CollectionService"),
    CoreGui = game:GetService("CoreGui"),
    Debris = game:GetService("Debris"),
    MarketplaceService = game:GetService("MarketplaceService")
}

local Player = Services.Players.LocalPlayer
local LP = Player
local CoinCollected = Services.ReplicatedStorage.Remotes.Gameplay.CoinCollected
local RoundStart = Services.ReplicatedStorage.Remotes.Gameplay.RoundStart
local RoundEnd = Services.ReplicatedStorage.Remotes.Gameplay.RoundEndFade

-- Состояния
local States = {
    autoResetEnabled = false,
    bag_full = false,
    resetting = false,
    start_position = nil,
    farming = false,
    gunDropESPToggled = false,
    shootMurdererEnabled = false,
    shootMurdererFrameSize = 10  -- Размер фрейма от 5 до 20, по умолчанию 10
}

-- Цвета для Highlight
local COLORS = {
    ESP_MURDER = Color3.fromRGB(225, 0, 0),
    ESP_SHERIFF = Color3.fromRGB(0, 0, 225),
    ESP_HERO = Color3.fromRGB(255, 250, 0),
    ESP_INNOCENT = Color3.fromRGB(0, 225, 0)
}

local StateManagers = {
    ESP = {
        Enabled = false,
        Murder = true,
        Sheriff = true,
        Hero = true,
        Innocent = true
    }
}

local Cache = {
    Highlights = {},
    HumanoidConnections = {},
    Players = {},
    Visibility = {},
    Roles = {}
}

local Connections = {
    Players = {},
    RunService = {}
}

-- Получение цвета Highlight по роли
local function GetHighlightColor(role)
    if role == "Murderer" then
        return COLORS.ESP_MURDER
    elseif role == "Sheriff" then
        return COLORS.ESP_SHERIFF
    elseif role == "Hero" then
        return COLORS.ESP_HERO
    else
        return COLORS.ESP_INNOCENT
    end
end

-- Безопасное удаление объектов
local function SafeDestroy(obj)
    pcall(function()
        if obj and obj.Parent then
            obj:Destroy()
        end
    end)
end

-- Проверка жив ли игрок
local function IsAlive(player)
    if not player or not player.Character then
        return false
    end
    
    local humanoid = player.Character:FindFirstChild("Humanoid")
    if not humanoid then
        return false
    end
    
    return humanoid.Health > 0 and humanoid.Parent ~= nil
end

-- Получение роли игрока
local function GetPlayerRole(player)
    if not player then return "Innocent" end
    
    -- Проверяем наличие оружия в инвентаре или персонаже
    local hasKnife = false
    local hasGun = false
    
    -- Проверяем Backpack
    if player.Backpack then
        if player.Backpack:FindFirstChild("Knife") then
            hasKnife = true
        end
        if player.Backpack:FindFirstChild("Gun") then
            hasGun = true
        end
    end
    
    -- Проверяем Character
    if player.Character then
        if player.Character:FindFirstChild("Knife") then
            hasKnife = true
        end
        if player.Character:FindFirstChild("Gun") then
            hasGun = true
        end
    end
    
    if hasKnife then
        return "Murderer"
    elseif hasGun then
        return "Sheriff"
    else
        return "Innocent"
    end
end

-- ESP функции
local function CreateHighlight(player)
    if not StateManagers.ESP.Enabled or player == LP then
        return nil
    end
    
    if not player or not player.Parent then
        return nil
    end
    
    local character = player.Character
    if not character or not character.Parent then
        return nil
    end
    
    -- Проверка существующего Highlight
    local existing = Cache.Highlights[player]
    if existing and existing.Parent then
        if existing.Adornee ~= character then
            existing.Adornee = character
        end
        existing.Enabled = true
        return existing
    end
    
    -- Удаление старого Highlight если он есть
    if existing then
        SafeDestroy(existing)
    end
    
    -- Проверка, жив ли игрок
    if not IsAlive(player) then
        return nil
    end
    
    -- Создание нового Highlight
    local highlight = Instance.new("Highlight")
    highlight.Name = "OnyxHighlight_" .. player.UserId
    highlight.Adornee = character
    highlight.FillTransparency = 0.7
    highlight.OutlineTransparency = 0.3
    highlight.DepthMode = Enum.HighlightDepthMode.AlwaysOnTop
    highlight.Enabled = true
    
    -- Установка цвета в зависимости от роли
    local role = GetPlayerRole(player)
    highlight.FillColor = GetHighlightColor(role)
    highlight.OutlineColor = GetHighlightColor(role)
    
    highlight.Parent = Services.Workspace
    Cache.Highlights[player] = highlight
    
    -- Очистка кэша при уничтожении
    highlight.Destroying:Once(function()
        Cache.Highlights[player] = nil
    end)
    
    return highlight
end

local function UpdateHighlightColor(player)
    local highlight = Cache.Highlights[player]
    if not highlight or not highlight.Parent or highlight.Adornee == nil then
        return false
    end
    
    -- Проверяем, жив ли игрок
    if not IsAlive(player) then
        highlight.Enabled = false
        return false
    end
    
    local role = GetPlayerRole(player)
    
    highlight.FillColor = GetHighlightColor(role)
    highlight.OutlineColor = GetHighlightColor(role)
    highlight.Enabled = true
    return true
end

local function UpdateAllHighlights()
    -- Создаем копию игроков для безопасной итерации
    local playersToUpdate = {}
    for _, player in ipairs(Services.Players:GetPlayers()) do
        if player ~= LP then
            playersToUpdate[player] = true
        end
    end
    
    -- Обновление Highlight элементов
    for player in pairs(playersToUpdate) do
        if player and player.Parent then
            local isAlive = IsAlive(player)
            
            -- Highlight
            if StateManagers.ESP.Enabled and isAlive then
                local highlight = Cache.Highlights[player]
                if highlight and highlight.Parent then
                    -- Проверяем, нужно ли показывать этого игрока
                    local role = GetPlayerRole(player)
                    local shouldShow = false
                    
                    if role == "Murderer" and StateManagers.ESP.Murder then
                        shouldShow = true
                    elseif role == "Sheriff" and StateManagers.ESP.Sheriff then
                        shouldShow = true
                    elseif role == "Hero" and StateManagers.ESP.Hero then
                        shouldShow = true
                    elseif role == "Innocent" and StateManagers.ESP.Innocent then
                        shouldShow = true
                    end
                    
                    if shouldShow then
                        -- Обновляем цвет и видимость
                        UpdateHighlightColor(player)
                    else
                        highlight.Enabled = false
                    end
                elseif player.Character then
                    -- Создаем новый Highlight
                    CreateHighlight(player)
                end
            else
                -- Если ESP выключен или игрок мертв, скрываем Highlight если он есть
                local highlight = Cache.Highlights[player]
                if highlight then
                    highlight.Enabled = false
                end
            end
        end
    end
end

-- Очистка всех Highlight
local function CleanupAllHighlights()
    for player, highlight in pairs(Cache.Highlights) do
        SafeDestroy(highlight)
    end
    Cache.Highlights = {}
end

-- Создание элементов интерфейса
local function createElement(className, properties)
    local element = Instance.new(className)
    for prop, value in pairs(properties) do
        if prop ~= "Parent" then
            element[prop] = value
        end
    end
    return element
end

-- Создание UI элементов с общими свойствами
local function createUIElement(className, parent, properties)
    local element = createElement(className, properties)
    element.Parent = parent
    return element
end

-- Основной GUI
local ScreenGui = createUIElement("ScreenGui", Services.CoreGui, {
    Name = "ShadowUI",
    ResetOnSpawn = false,
    ZIndexBehavior = Enum.ZIndexBehavior.Sibling,
    DisplayOrder = 10  -- Высокий DisplayOrder для основного UI
})

local MainFrame = createUIElement("Frame", ScreenGui, {
    BackgroundColor3 = Color3.fromRGB(15, 15, 15),
    BackgroundTransparency = 0.08,
    BorderSizePixel = 0,
    Size = UDim2.new(0, 500, 0, 300),
    AnchorPoint = Vector2.new(0.5, 0.5),
    Position = UDim2.new(0.5, 0, 0.5, 0)
})

createUIElement("UICorner", MainFrame, {CornerRadius = UDim.new(0, 10)})
createUIElement("UIStroke", MainFrame, {
    Color = Color3.fromRGB(230, 57, 51),
    Thickness = 1.8,
    Transparency = 0.05
})

-- Заголовок
local TitleContainer = createUIElement("Frame", MainFrame, {
    BackgroundTransparency = 1,
    Position = UDim2.new(0.04, 0, 0.05, 0),
    Size = UDim2.new(0.9, 0, 0, 25)
})

local TitleIcon = createUIElement("ImageLabel", TitleContainer, {
    Size = UDim2.new(0, 25, 0, 25),
    BackgroundTransparency = 1,
    Image = "rbxthumb://type=Asset&id=93388705336185&w=420&h=420",
    ImageColor3 = Color3.fromRGB(230, 57, 51)
})

local Title = createUIElement("TextLabel", TitleContainer, {
    BackgroundTransparency = 1,
    Position = UDim2.new(0, 30, 0, 0),
    Size = UDim2.new(1, -30, 1, 0),
    Font = Enum.Font.GothamBold,
    Text = "Shadow Script | Murder Mystery 2",
    TextColor3 = Color3.fromRGB(230, 57, 51),
    TextSize = 15,
    TextXAlignment = Enum.TextXAlignment.Left
})

createUIElement("Frame", MainFrame, {
    BackgroundColor3 = Color3.fromRGB(230, 57, 51),
    BorderSizePixel = 0,
    Size = UDim2.new(0.92, 0, 0, 1),
    Position = UDim2.new(0.04, 0, 0.155, 0)
})

-- Вкладки
local Tabs = {"Main", "Visual", "Combat", "Emotes", "Teleport", "Auto Farm", "Misc"}
local TabButtons = {}
local TabPages = {}

local PageScrollFrame = createUIElement("ScrollingFrame", MainFrame, {
    BackgroundTransparency = 1,
    Position = UDim2.new(0.04, 0, 0.19, 0),
    Size = UDim2.new(0.6, 0, 0.75, 0),
    ScrollBarThickness = 4,
    ScrollBarImageColor3 = Color3.fromRGB(230, 57, 51),
    CanvasSize = UDim2.new(0, 0, 0, 0),
    AutomaticCanvasSize = Enum.AutomaticSize.Y
})

local TabsScrollFrame = createUIElement("ScrollingFrame", MainFrame, {
    BackgroundTransparency = 1,
    Position = UDim2.new(0.70, 0, 0.19, 0),
    Size = UDim2.new(0.27, 0, 0.75, 0),
    ScrollBarThickness = 4,
    ScrollBarImageColor3 = Color3.fromRGB(230, 57, 51),
    CanvasSize = UDim2.new(0, 0, 0, 0),
    AutomaticCanvasSize = Enum.AutomaticSize.Y
})

local TabsContainer = createUIElement("Frame", TabsScrollFrame, {
    BackgroundTransparency = 1,
    Size = UDim2.new(1, 0, 0, 0),
    AutomaticSize = Enum.AutomaticSize.Y
})

createUIElement("UIListLayout", TabsContainer, {
    Padding = UDim.new(0, 8),
    SortOrder = Enum.SortOrder.LayoutOrder
})

-- Функция обновления вида кнопок
local function UpdateButtonVisual(button, isActive)
    button.BackgroundTransparency = isActive and 0 or 0.1
    button.BackgroundColor3 = isActive and Color3.fromRGB(20,20,20) or Color3.fromRGB(15,15,15)
    
    local stroke = button:FindFirstChild("ButtonStroke")
    if stroke then
        stroke.Thickness = isActive and 3 or 2
        stroke.Color = isActive and Color3.fromRGB(230,57,51) or Color3.fromRGB(200,50,47)
    end
end

-- Таблица иконок для вкладок
local tabIcons = {
    ["Main"] = "rbxthumb://type=Asset&id=72808987642452&w=420&h=420",
    ["Visual"] = "rbxthumb://type=Asset&id=134788157396683&w=420&h=420",
    ["Combat"] = "rbxthumb://type=Asset&id=125724093327848&w=420&h=420",
    ["Emotes"] = "rbxthumb://type=Asset&id=133473827960783&w=420&h=420",
    ["Teleport"] = "rbxthumb://type=Asset&id=115511057783647&w=420&h=420",
    ["Auto Farm"] = "rbxthumb://type=Asset&id=114528728360623&w=420&h=420",
    ["Misc"] = "rbxthumb://type=Asset&id=118821455550069&w=420&h=420"
}

-- Создание кнопок вкладок
for i, tabName in ipairs(Tabs) do
    local Button = createUIElement("TextButton", TabsContainer, {
        Name = tabName .. "_TabButton",
        Size = UDim2.new(1, 0, 0, 38),
        BackgroundColor3 = Color3.fromRGB(15, 15, 15),
        BackgroundTransparency = 0.1,
        BorderSizePixel = 0,
        Text = tabName,
        TextColor3 = Color3.fromRGB(255, 255, 255),
        Font = Enum.Font.GothamBold,
        TextSize = 14,
        RichText = false,
        AutoButtonColor = false,
        LayoutOrder = i
    })

    Button.MouseButton1Click:Connect(playButtonSound)

    -- Добавление иконки
    local iconId = tabIcons[tabName]
    if iconId then
        createUIElement("ImageLabel", Button, {
            Size = UDim2.new(0, 20, 0, 20),
            Position = UDim2.new(0, 5, 0.5, -10),
            BackgroundTransparency = 1,
            Image = iconId
        })
    end

    -- Стилизация кнопки
    createUIElement("UICorner", Button, {CornerRadius = UDim.new(0, 15)})
    createUIElement("UIStroke", Button, {
        Name = "ButtonStroke",
        Color = Color3.fromRGB(200,50,47),
        Thickness = 2,
        ApplyStrokeMode = Enum.ApplyStrokeMode.Border
    })

    -- Создание страницы
    local Page = createUIElement("Frame", PageScrollFrame, {
        Size = UDim2.new(1, 0, 0, 0),
        BackgroundTransparency = 1,
        Visible = false,
        AutomaticSize = Enum.AutomaticSize.Y
    })

    TabButtons[tabName] = Button
    TabPages[tabName] = Page
end

-- Переключение вкладок
local function SwitchTab(tab)
    for name, page in pairs(TabPages) do
        page.Visible = false
    end
    for name, btn in pairs(TabButtons) do
        UpdateButtonVisual(btn, false)
    end
    if TabPages[tab] then
        TabPages[tab].Visible = true
    end
    if TabButtons[tab] then
        UpdateButtonVisual(TabButtons[tab], true)
    end
end

SwitchTab("Main")

-- Обработчики кнопок вкладок
for tabName, button in pairs(TabButtons) do
    button.MouseButton1Click:Connect(function()
        SwitchTab(tabName)
    end)
    
    button.MouseEnter:Connect(function()
        if TabPages[tabName] and not TabPages[tabName].Visible then
            button.BackgroundTransparency = 0
            button.BackgroundColor3 = Color3.fromRGB(18,18,18)
        end
    end)
    
    button.MouseLeave:Connect(function()
        if TabPages[tabName] and not TabPages[tabName].Visible then
            button.BackgroundTransparency = 0.1
            button.BackgroundColor3 = Color3.fromRGB(15,15,15)
        end
    end)
end

-- Страница Main
local MainPage = TabPages["Main"]

-- Заголовок для Main страницы
createUIElement("TextLabel", MainPage, {
    Size = UDim2.new(1, 0, 0, 30),
    BackgroundTransparency = 1,
    Text = "Main Page",
    TextColor3 = Color3.fromRGB(255, 255, 255),
    Font = Enum.Font.GothamBold,
    TextSize = 18,
    Position = UDim2.new(0, 0, 0, 0)
})

local ProfileContainer = createUIElement("Frame", MainPage, {
    BackgroundColor3 = Color3.fromRGB(20,20,20),
    BackgroundTransparency = 0.1,
    Size = UDim2.new(1, -10, 0, 120),
    Position = UDim2.new(0, 0, 0, 40)
})

createUIElement("UICorner", ProfileContainer, {CornerRadius = UDim.new(0, 10)})
createUIElement("UIStroke", ProfileContainer, {
    Color = Color3.fromRGB(230,57,51),
    Thickness = 1.8
})

local Avatar = createUIElement("ImageLabel", ProfileContainer, {
    BackgroundTransparency = 1,
    Size = UDim2.new(0, 90, 0, 90),
    Position = UDim2.new(0, 10, 0, 15),
    Image = "rbxthumb://type=AvatarHeadShot&id="..Player.UserId.."&w=420&h=420"
})

createUIElement("UICorner", Avatar, {CornerRadius = UDim.new(0, 8)})

local Info = createUIElement("Frame", ProfileContainer, {
    Size = UDim2.new(1, -120, 1, -20),
    Position = UDim2.new(0, 110, 0, 10),
    BackgroundTransparency = 1
})

-- Функция добавления информации
local function NewInfo(name, value, order)
    return createUIElement("TextLabel", Info, {
        Size = UDim2.new(1, 0, 0, 20),
        Position = UDim2.new(0, 0, 0, order * 22),
        BackgroundTransparency = 1,
        Font = Enum.Font.Gotham,
        TextXAlignment = Enum.TextXAlignment.Left,
        TextColor3 = Color3.fromRGB(255, 255, 255),
        TextSize = 14,
        Text = name .. ": " .. value
    })
end

-- Информация об исполнителе
local executor = "Unknown"
pcall(function()
    local executors = {
        {func = identifyexecutor, type = "function"},
        {func = getexecutorname, type = "function"},
        {check = syn, name = "Synapse X"},
        {check = PROTOSMASHER_LOADED, name = "ProtoSmasher"},
        {check = KRNL_LOADED, name = "Krnl"}
    }
    
    for _, exec in ipairs(executors) do
        if exec.func and type(exec.func) == exec.type then
            executor = exec.func()
            break
        elseif exec.check then
            executor = exec.name
            break
        end
    end
end)

local robloxVersion = "Unknown"
pcall(function()
    robloxVersion = tostring(version())
end)

NewInfo("Username", Player.Name, 0)
NewInfo("Display Name", Player.DisplayName, 1)
NewInfo("Roblox Version", robloxVersion, 2)
NewInfo("Executor", executor, 3)

-- Speed and Jump Sliders Container
local SpeedJumpContainer = createUIElement("Frame", MainPage, {
    BackgroundColor3 = Color3.fromRGB(20,20,20),
    BackgroundTransparency = 0.1,
    Size = UDim2.new(1, -10, 0, 170),
    Position = UDim2.new(0, 0, 0, 170)
})

createUIElement("UICorner", SpeedJumpContainer, {CornerRadius = UDim.new(0, 10)})
createUIElement("UIStroke", SpeedJumpContainer, {
    Color = Color3.fromRGB(230,57,51),
    Thickness = 1.8
})

-- Speed Slider
local SpeedContainer = createUIElement("Frame", SpeedJumpContainer, {
    BackgroundColor3 = Color3.fromRGB(25,25,25),
    BackgroundTransparency = 0.1,
    Size = UDim2.new(1, -20, 0, 45),
    Position = UDim2.new(0, 10, 0, 10)
})

createUIElement("UICorner", SpeedContainer, {CornerRadius = UDim.new(0, 8)})

local SpeedLabel = createUIElement("TextLabel", SpeedContainer, {
    Size = UDim2.new(0.6, 0, 0, 20),
    Position = UDim2.new(0, 10, 0, 5),
    BackgroundTransparency = 1,
    Font = Enum.Font.GothamBold,
    Text = "Speed: 16",
    TextColor3 = Color3.fromRGB(255, 255, 255),
    TextSize = 14,
    TextXAlignment = Enum.TextXAlignment.Left
})

local speedSliderFrame = createUIElement("Frame", SpeedContainer, {
    Size = UDim2.new(0.9, 0, 0, 15),
    Position = UDim2.new(0.05, 0, 0, 25),
    BackgroundColor3 = Color3.fromRGB(50, 50, 50),
    BorderSizePixel = 0
})

createUIElement("UICorner", speedSliderFrame, {CornerRadius = UDim.new(0, 7)})

local speedSliderTrack = createUIElement("Frame", speedSliderFrame, {
    Size = UDim2.new(0.08, 0, 1, 0),
    BackgroundColor3 = Color3.fromRGB(230, 57, 51),
    BorderSizePixel = 0
})

createUIElement("UICorner", speedSliderTrack, {CornerRadius = UDim.new(0, 7)})

local speedSliderButton = createUIElement("TextButton", speedSliderFrame, {
    Size = UDim2.new(0, 20, 0, 20),
    Position = UDim2.new(0.08, -10, 0.5, -10),
    BackgroundColor3 = Color3.fromRGB(255, 255, 255),
    BorderSizePixel = 0,
    Text = "",
    AutoButtonColor = false
})

createUIElement("UICorner", speedSliderButton, {CornerRadius = UDim.new(0, 10)})
createUIElement("UIStroke", speedSliderButton, {
    Color = Color3.fromRGB(200, 200, 200),
    Thickness = 2
})

-- Jump Slider
local JumpContainer = createUIElement("Frame", SpeedJumpContainer, {
    BackgroundColor3 = Color3.fromRGB(25,25,25),
    BackgroundTransparency = 0.1,
    Size = UDim2.new(1, -20, 0, 45),
    Position = UDim2.new(0, 10, 0, 65)
})

createUIElement("UICorner", JumpContainer, {CornerRadius = UDim.new(0, 8)})

local JumpLabel = createUIElement("TextLabel", JumpContainer, {
    Size = UDim2.new(0.6, 0, 0, 20),
    Position = UDim2.new(0, 10, 0, 5),
    BackgroundTransparency = 1,
    Font = Enum.Font.GothamBold,
    Text = "Jump: 50",
    TextColor3 = Color3.fromRGB(255, 255, 255),
    TextSize = 14,
    TextXAlignment = Enum.TextXAlignment.Left
})

local jumpSliderFrame = createUIElement("Frame", JumpContainer, {
    Size = UDim2.new(0.9, 0, 0, 15),
    Position = UDim2.new(0.05, 0, 0, 25),
    BackgroundColor3 = Color3.fromRGB(50, 50, 50),
    BorderSizePixel = 0
})

createUIElement("UICorner", jumpSliderFrame, {CornerRadius = UDim.new(0, 7)})

local jumpSliderTrack = createUIElement("Frame", jumpSliderFrame, {
    Size = UDim2.new(0.25, 0, 1, 0),
    BackgroundColor3 = Color3.fromRGB(230, 57, 51),
    BorderSizePixel = 0
})

createUIElement("UICorner", jumpSliderTrack, {CornerRadius = UDim.new(0, 7)})

local jumpSliderButton = createUIElement("TextButton", jumpSliderFrame, {
    Size = UDim2.new(0, 20, 0, 20),
    Position = UDim2.new(0.25, -10, 0.5, -10),
    BackgroundColor3 = Color3.fromRGB(255, 255, 255),
    BorderSizePixel = 0,
    Text = "",
    AutoButtonColor = false
})

createUIElement("UICorner", jumpSliderButton, {CornerRadius = UDim.new(0, 10)})
createUIElement("UIStroke", jumpSliderButton, {
    Color = Color3.fromRGB(200, 200, 200),
    Thickness = 2
})

-- Reset Button
local ResetButton = createUIElement("TextButton", SpeedJumpContainer, {
    Size = UDim2.new(0.9, 0, 0, 35),
    Position = UDim2.new(0.05, 0, 0, 120),
    BackgroundColor3 = Color3.fromRGB(230, 57, 51),
    BackgroundTransparency = 0,
    BorderSizePixel = 0,
    Text = "Reset",
    TextColor3 = Color3.fromRGB(255, 255, 255),
    Font = Enum.Font.GothamBold,
    TextSize = 14,
    AutoButtonColor = false
})

ResetButton.MouseButton1Click:Connect(playButtonSound)

createUIElement("UICorner", ResetButton, {CornerRadius = UDim.new(0, 8)})
createUIElement("UIStroke", ResetButton, {
    Color = Color3.fromRGB(200, 50, 47),
    Thickness = 2
})

-- Hover эффекты для Reset Button
ResetButton.MouseEnter:Connect(function()
    ResetButton.BackgroundColor3 = Color3.fromRGB(210, 47, 41)
end)

ResetButton.MouseLeave:Connect(function()
    ResetButton.BackgroundColor3 = Color3.fromRGB(230, 57, 51)
end)

-- Функции для обновления значений слайдеров
local function updateSpeedSlider(value)
    -- Ограничиваем значение от 0 до 1
    local normalizedValue = math.clamp(value, 0, 1)
    
    -- Обновляем визуальные элементы
    speedSliderTrack.Size = UDim2.new(normalizedValue, 0, 1, 0)
    speedSliderButton.Position = UDim2.new(normalizedValue, -10, 0.5, -10)
    
    -- Обновляем текст (от 1 до 200)
    local speedValue = math.floor(1 + normalizedValue * 199)
    SpeedLabel.Text = "Speed: " .. speedValue
    
    -- ЛОГИКА ИЗ ПРИВЕДЕННОГО КОДА: Изменяем скорость персонажа
    if Player.Character then
        local humanoid = Player.Character:FindFirstChildOfClass("Humanoid")
        if humanoid then
            humanoid.WalkSpeed = speedValue
        end
    end
end

local function updateJumpSlider(value)
    -- Ограничиваем значение от 0 до 1
    local normalizedValue = math.clamp(value, 0, 1)
    
    -- Обновляем визуальные элементы
    jumpSliderTrack.Size = UDim2.new(normalizedValue, 0, 1, 0)
    jumpSliderButton.Position = UDim2.new(normalizedValue, -10, 0.5, -10)
    
    -- Обновляем текст (от 1 до 200)
    local jumpValue = math.floor(1 + normalizedValue * 199)
    JumpLabel.Text = "Jump: " .. jumpValue
    
    -- ЛОГИКА ИЗ ПРИВЕДЕННОГО КОДА: Изменяем прыжок персонажа
    if Player.Character then
        local humanoid = Player.Character:FindFirstChildOfClass("Humanoid")
        if humanoid then
            humanoid.JumpPower = jumpValue
        end
    end
end

-- Переменные для отслеживания перетаскивания
local draggingSpeed = false
local draggingJump = false
local currentTouchId = nil

-- Функции для работы со слайдерами (работают на ПК и телефоне)
local function beginDrag(sliderType, input)
    -- Проверяем тип ввода
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        -- Для мыши
        if sliderType == "speed" then
            draggingSpeed = true
        else
            draggingJump = true
        end
        return true
    elseif input.UserInputType == Enum.UserInputType.Touch then
        -- Для телефона
        if currentTouchId == nil then
            currentTouchId = input
            if sliderType == "speed" then
                draggingSpeed = true
            else
                draggingJump = true
            end
            return true
        end
    end
    return false
end

local function endDrag(sliderType, input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 then
        if sliderType == "speed" then
            draggingSpeed = false
        else
            draggingJump = false
        end
        currentTouchId = nil
    elseif input.UserInputType == Enum.UserInputType.Touch then
        -- Проверяем, что это тот же тач
        if currentTouchId == input then
            if sliderType == "speed" then
                draggingSpeed = false
            else
                draggingJump = false
            end
            currentTouchId = nil
        end
    end
end

local function updateSliderPosition(sliderType, input)
    -- Проверяем, какой слайдер активен
    local isDragging = false
    local sliderFrame = nil
    local updateFunction = nil
    
    if sliderType == "speed" then
        isDragging = draggingSpeed
        sliderFrame = speedSliderFrame
        updateFunction = updateSpeedSlider
    else
        isDragging = draggingJump
        sliderFrame = jumpSliderFrame
        updateFunction = updateJumpSlider
    end
    
    if not isDragging then return end
    
    -- Для тача проверяем, что это тот же тач
    if input.UserInputType == Enum.UserInputType.Touch and currentTouchId ~= input then
        return
    end
    
    -- Вычисляем относительную позицию
    local relativeX = (input.Position.X - sliderFrame.AbsolutePosition.X) / sliderFrame.AbsoluteSize.X
    updateFunction(relativeX)
end

-- Обработчики для Speed Slider
speedSliderButton.InputBegan:Connect(function(input)
    if beginDrag("speed", input) then
        playButtonSound()
    end
end)

speedSliderButton.InputEnded:Connect(function(input)
    endDrag("speed", input)
end)

speedSliderFrame.InputBegan:Connect(function(input)
    if beginDrag("speed", input) then
        playButtonSound()
        updateSliderPosition("speed", input)
    end
end)

speedSliderFrame.InputEnded:Connect(function(input)
    endDrag("speed", input)
end)

-- Обработчики для Jump Slider
jumpSliderButton.InputBegan:Connect(function(input)
    if beginDrag("jump", input) then
        playButtonSound()
    end
end)

jumpSliderButton.InputEnded:Connect(function(input)
    endDrag("jump", input)
end)

jumpSliderFrame.InputBegan:Connect(function(input)
    if beginDrag("jump", input) then
        playButtonSound()
        updateSliderPosition("jump", input)
    end
end)

jumpSliderFrame.InputEnded:Connect(function(input)
    endDrag("jump", input)
end)

-- Обработка перемещения
Services.UserInputService.InputChanged:Connect(function(input)
    if draggingSpeed then
        updateSliderPosition("speed", input)
    end
    if draggingJump then
        updateSliderPosition("jump", input)
    end
end)

-- Обработка окончания тача
Services.UserInputService.TouchEnded:Connect(function(input)
    if currentTouchId == input then
        if draggingSpeed then
            endDrag("speed", input)
        end
        if draggingJump then
            endDrag("jump", input)
        end
    end
end)

-- Улучшаем отзывчивость для телефона
speedSliderButton.Active = true
speedSliderButton.Selectable = true
speedSliderFrame.Active = true

jumpSliderButton.Active = true
jumpSliderButton.Selectable = true
jumpSliderFrame.Active = true

-- Функция сброса слайдеров
ResetButton.MouseButton1Click:Connect(function()
    -- Сброс Speed слайдера
    updateSpeedSlider(0.075) -- 16/200 ≈ 0.08
    updateJumpSlider(0.246)  -- 50/200 ≈ 0.25
end)

-- Эффекты при наведении на кнопки слайдеров (только для ПК)
speedSliderButton.MouseEnter:Connect(function()
    if not draggingSpeed then
        speedSliderButton.BackgroundColor3 = Color3.fromRGB(230, 230, 230)
    end
end)

speedSliderButton.MouseLeave:Connect(function()
    if not draggingSpeed then
        speedSliderButton.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
    end
end)

jumpSliderButton.MouseEnter:Connect(function()
    if not draggingJump then
        jumpSliderButton.BackgroundColor3 = Color3.fromRGB(230, 230, 230)
    end
end)

jumpSliderButton.MouseLeave:Connect(function()
    if not draggingJump then
        jumpSliderButton.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
    end
end)

-- Применяем настройки при появлении нового персонажа (ЛОГИКА ИЗ ПРИВЕДЕННОГО КОДА)
Player.CharacterAdded:Connect(function(character)
    task.wait(0.5) -- Ждем загрузки персонажа
    
    -- Восстанавливаем сохраненные значения скорости и прыжка
    local speedValue = tonumber(SpeedLabel.Text:match("%d+")) or 16
    local jumpValue = tonumber(JumpLabel.Text:match("%d+")) or 50
    
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        humanoid.WalkSpeed = speedValue
        humanoid.JumpPower = jumpValue
    end
end)

-- Инициализация текущего персонажа
if Player.Character then
    local speedValue = tonumber(SpeedLabel.Text:match("%d+")) or 16
    local jumpValue = tonumber(JumpLabel.Text:match("%d+")) or 50
    
    local humanoid = Player.Character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        humanoid.WalkSpeed = speedValue
        humanoid.JumpPower = jumpValue
    end
end

-- Fly Toggle Container
local FlyContainer = createUIElement("Frame", MainPage, {
    BackgroundColor3 = Color3.fromRGB(20,20,20),
    BackgroundTransparency = 0.1,
    Size = UDim2.new(1, -10, 0, 50),
    Position = UDim2.new(0, 0, 0, 350)
})

createUIElement("UICorner", FlyContainer, {CornerRadius = UDim.new(0, 10)})
createUIElement("UIStroke", FlyContainer, {
    Color = Color3.fromRGB(230,57,51),
    Thickness = 1.8
})

-- Заголовок Fly
createUIElement("TextLabel", FlyContainer, {
    Size = UDim2.new(0.6, 0, 1, 0),
    Position = UDim2.new(0, 10, 0, 0),
    BackgroundTransparency = 1,
    Font = Enum.Font.GothamBold,
    Text = "Fly",
    TextColor3 = Color3.fromRGB(255, 255, 255),
    TextSize = 16,
    TextXAlignment = Enum.TextXAlignment.Left
})

-- Логика полета как в примере
local FLY_ENABLED = false
local FLY_SPEED = 1
local FLY_CTRL = {f = 0, b = 0, l = 0, r = 0}
local FLY_LAST_CTRL = {f = 0, b = 0, l = 0, r = 0}
local FLY_BG = nil
local FLY_BV = nil
local FLY_CURRENT_SPEED = 0
local FLY_MAX_SPEED = 50
local FLY_TP_WALKING = false
local FLY_HB_CONNECTIONS = {}

-- Тоггл Fly
local FlyToggle = createUIElement("TextButton", FlyContainer, {
    Size = UDim2.new(0, 60, 0, 30),
    Position = UDim2.new(1, -70, 0.5, -15),
    BackgroundColor3 = Color3.fromRGB(50, 50, 50),
    BorderSizePixel = 0,
    Text = "OFF",
    TextColor3 = Color3.fromRGB(255, 255, 255),
    Font = Enum.Font.GothamBold,
    TextSize = 12,
    AutoButtonColor = false
})

FlyToggle.MouseButton1Click:Connect(playButtonSound)

createUIElement("UICorner", FlyToggle, {CornerRadius = UDim.new(0, 15)})
local FlyToggleStroke = createUIElement("UIStroke", FlyToggle, {
    Color = Color3.fromRGB(100, 100, 100),
    Thickness = 2
})

-- Функция включения полета (логика из примера)
local function startFly()
    FLY_ENABLED = true
    local player = Player
    local character = player.Character
    
    if not character then 
        FLY_ENABLED = false
        return 
    end
    
    -- Отключаем анимации
    local animate = character:FindFirstChild("Animate")
    if animate then
        animate.Disabled = true
    end
    
    -- Отключаем все анимационные треки
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if not humanoid then
        FLY_ENABLED = false
        return
    end
    
    for _, track in next, humanoid:GetPlayingAnimationTracks() do
        track:AdjustSpeed(0)
    end
    
    -- Отключаем все состояния как в примере
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Flying, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Landed, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.PlatformStanding, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Seated, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.StrafingNoPhysics, false)
    humanoid:SetStateEnabled(Enum.HumanoidStateType.Swimming, false)
    humanoid:ChangeState(Enum.HumanoidStateType.Swimming)
    humanoid.PlatformStand = true
    
    -- Создаем телепорт-ходьбу как в примере
    for i = 1, FLY_SPEED do
        local conn = Services.RunService.Heartbeat:Connect(function()
            if FLY_TP_WALKING and character and humanoid and humanoid.Parent then
                if humanoid.MoveDirection.Magnitude > 0 then
                    character:TranslateBy(humanoid.MoveDirection)
                end
            end
        end)
        table.insert(FLY_HB_CONNECTIONS, conn)
    end
    FLY_TP_WALKING = true
    
    -- Определяем часть тела для R6/R15
    local bodyPart = nil
    if humanoid.RigType == Enum.HumanoidRigType.R6 then
        bodyPart = character:FindFirstChild("Torso")
    else
        bodyPart = character:FindFirstChild("UpperTorso") or character:FindFirstChild("HumanoidRootPart")
    end
    
    if not bodyPart then 
        FLY_ENABLED = false
        return 
    end
    
    -- Создаём BodyGyro
    FLY_BG = Instance.new("BodyGyro")
    FLY_BG.P = 9e4
    FLY_BG.maxTorque = Vector3.new(9e9, 9e9, 9e9)
    FLY_BG.cframe = bodyPart.CFrame
    FLY_BG.Parent = bodyPart
    
    -- Создаём BodyVelocity
    FLY_BV = Instance.new("BodyVelocity")
    FLY_BV.velocity = Vector3.new(0, 0.1, 0)
    FLY_BV.maxForce = Vector3.new(9e9, 9e9, 9e9)
    FLY_BV.Parent = bodyPart
    
    -- Основной цикл полета
    task.spawn(function()
        FLY_CURRENT_SPEED = 0
        
        while FLY_ENABLED and character and humanoid and humanoid.Health > 0 do
            Services.RunService.RenderStepped:Wait()
            
            -- Проверяем, что FLY_BV все еще существует
            if not FLY_BV or not FLY_BV.Parent then
                break -- Выходим из цикла если BodyVelocity был удален
            end
            
            -- Обновляем управление
            local moveX, moveZ = 0, 0
            
            if Services.UserInputService:IsKeyDown(Enum.KeyCode.W) then
                moveZ = moveZ + 1
            end
            if Services.UserInputService:IsKeyDown(Enum.KeyCode.S) then
                moveZ = moveZ - 1
            end
            if Services.UserInputService:IsKeyDown(Enum.KeyCode.A) then
                moveX = moveX - 1
            end
            if Services.UserInputService:IsKeyDown(Enum.KeyCode.D) then
                moveX = moveX + 1
            end
            
            FLY_CTRL = {f = moveZ > 0 and 1 or 0, b = moveZ < 0 and 1 or 0, 
                        l = moveX < 0 and 1 or 0, r = moveX > 0 and 1 or 0}
            
            -- Логика скорости
            local ctrlSum = FLY_CTRL.l + FLY_CTRL.r + FLY_CTRL.f + FLY_CTRL.b
            if ctrlSum ~= 0 then
                FLY_CURRENT_SPEED = FLY_CURRENT_SPEED + 0.5 + (FLY_CURRENT_SPEED / FLY_MAX_SPEED)
                if FLY_CURRENT_SPEED > FLY_MAX_SPEED then
                    FLY_CURRENT_SPEED = FLY_MAX_SPEED
                end
            elseif FLY_CURRENT_SPEED > 0 then
                FLY_CURRENT_SPEED = FLY_CURRENT_SPEED - 1
                if FLY_CURRENT_SPEED < 0 then
                    FLY_CURRENT_SPEED = 0
                end
            end
            
            -- Применяем движение (только если FLY_BV существует)
            if FLY_BV and FLY_BV.Parent then
                if (FLY_CTRL.l + FLY_CTRL.r) ~= 0 or (FLY_CTRL.f + FLY_CTRL.b) ~= 0 then
                    local camera = workspace.CurrentCamera
                    if camera then
                        FLY_BV.velocity = ((camera.CoordinateFrame.lookVector * (FLY_CTRL.f + FLY_CTRL.b)) + 
                                          ((camera.CoordinateFrame * CFrame.new(FLY_CTRL.l + FLY_CTRL.r, 
                                          (FLY_CTRL.f + FLY_CTRL.b) * 0.2, 0).p) - 
                                          camera.CoordinateFrame.p)) * FLY_CURRENT_SPEED
                        FLY_LAST_CTRL = {f = FLY_CTRL.f, b = FLY_CTRL.b, l = FLY_CTRL.l, r = FLY_CTRL.r}
                    end
                elseif (FLY_CTRL.l + FLY_CTRL.r) == 0 and (FLY_CTRL.f + FLY_CTRL.b) == 0 and FLY_CURRENT_SPEED > 0 then
                    local camera = workspace.CurrentCamera
                    if camera then
                        FLY_BV.velocity = ((camera.CoordinateFrame.lookVector * (FLY_LAST_CTRL.f + FLY_LAST_CTRL.b)) + 
                                          ((camera.CoordinateFrame * CFrame.new(FLY_LAST_CTRL.l + FLY_LAST_CTRL.r, 
                                          (FLY_LAST_CTRL.f + FLY_LAST_CTRL.b) * 0.2, 0).p) - 
                                          camera.CoordinateFrame.p)) * FLY_CURRENT_SPEED
                    end
                else
                    FLY_BV.velocity = Vector3.new(0, 0, 0)
                end
            end
            
            -- Обновляем BodyGyro (только если существует)
            if FLY_BG and FLY_BG.Parent then
                local camera = workspace.CurrentCamera
                if camera then
                    FLY_BG.cframe = camera.CoordinateFrame * 
                                   CFrame.Angles(-math.rad((FLY_CTRL.f + FLY_CTRL.b) * 50 * FLY_CURRENT_SPEED / FLY_MAX_SPEED), 0, 0)
                end
            end
        end
        
        -- Если цикл завершился, но FLY_ENABLED еще true, отключаем полет
        if FLY_ENABLED then
            FLY_ENABLED = false
            FlyToggle.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
            FlyToggle.Text = "OFF"
            FlyToggleStroke.Color = Color3.fromRGB(100, 100, 100)
        end
    end)
end

-- Функция выключения полета
local function stopFly()
    FLY_ENABLED = false
    FLY_TP_WALKING = false
    
    -- Отключаем все Heartbeat соединения
    for _, conn in ipairs(FLY_HB_CONNECTIONS) do
        pcall(function() conn:Disconnect() end)
    end
    FLY_HB_CONNECTIONS = {}
    
    -- Удаляем BodyGyro и BodyVelocity
    if FLY_BG then
        pcall(function()
            if FLY_BG.Parent then
                FLY_BG:Destroy()
            end
        end)
        FLY_BG = nil
    end
    
    if FLY_BV then
        pcall(function()
            if FLY_BV.Parent then
                FLY_BV:Destroy()
            end
        end)
        FLY_BV = nil
    end
    
    -- Восстанавливаем персонажа
    local player = Player
    local character = player.Character
    
    if character then
        local humanoid = character:FindFirstChildOfClass("Humanoid")
        if humanoid then
            pcall(function()
                -- Включаем все состояния обратно
                humanoid:SetStateEnabled(Enum.HumanoidStateType.Climbing, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.FallingDown, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.Flying, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.Freefall, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.GettingUp, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.Jumping, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.Landed, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.Physics, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.PlatformStanding, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.Ragdoll, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.Running, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.RunningNoPhysics, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.Seated, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.StrafingNoPhysics, true)
                humanoid:SetStateEnabled(Enum.HumanoidStateType.Swimming, true)
                humanoid:ChangeState(Enum.HumanoidStateType.RunningNoPhysics)
                humanoid.PlatformStand = false
            end)
        end
        
        -- Включаем анимации
        local animate = character:FindFirstChild("Animate")
        if animate then
            animate.Disabled = false
        end
    end
    
    -- Сбрасываем переменные
    FLY_CTRL = {f = 0, b = 0, l = 0, r = 0}
    FLY_LAST_CTRL = {f = 0, b = 0, l = 0, r = 0}
    FLY_CURRENT_SPEED = 0
end

-- Обработчик тоггла
FlyToggle.MouseButton1Click:Connect(function()
    if FLY_ENABLED then
        FlyToggle.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
        FlyToggle.Text = "OFF"
        FlyToggleStroke.Color = Color3.fromRGB(100, 100, 100)
        stopFly()
    else
        FlyToggle.BackgroundColor3 = Color3.fromRGB(230, 57, 51)
        FlyToggle.Text = "ON"
        FlyToggleStroke.Color = Color3.fromRGB(200, 50, 47)
        startFly()
    end
end)

-- Обработчик клавиш для движения вверх/вниз
local upPressed = false
local downPressed = false

Services.UserInputService.InputBegan:Connect(function(input, gameProcessed)
    if not gameProcessed and FLY_ENABLED and Player.Character then
        local rootPart = Player.Character:FindFirstChild("HumanoidRootPart")
        if not rootPart then return end
        
        if input.KeyCode == Enum.KeyCode.Space then
            upPressed = true
            -- Движение вверх
            while upPressed and FLY_ENABLED do
                if rootPart and rootPart.Parent then
                    rootPart.CFrame = rootPart.CFrame * CFrame.new(0, 3, 0)
                end
                task.wait()
            end
        elseif input.KeyCode == Enum.KeyCode.LeftControl or input.KeyCode == Enum.KeyCode.LeftShift then
            downPressed = true
            -- Движение вниз
            while downPressed and FLY_ENABLED do
                if rootPart and rootPart.Parent then
                    rootPart.CFrame = rootPart.CFrame * CFrame.new(0, -3, 0)
                end
                task.wait()
            end
        end
    end
end)

Services.UserInputService.InputEnded:Connect(function(input)
    if input.KeyCode == Enum.KeyCode.Space then
        upPressed = false
    elseif input.KeyCode == Enum.KeyCode.LeftControl or input.KeyCode == Enum.KeyCode.LeftShift then
        downPressed = false
    end
end)

-- Обработчик для персонажа
Player.CharacterAdded:Connect(function(character)
    task.wait(0.7)
    
    -- Автоматически выключаем полет при респавне
    if FLY_ENABLED then
        FLY_ENABLED = false
        FlyToggle.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
        FlyToggle.Text = "OFF"
        FlyToggleStroke.Color = Color3.fromRGB(100, 100, 100)
        stopFly()
    end
    
    -- Восстанавливаем нормальное состояние
    local humanoid = character:FindFirstChildOfClass("Humanoid")
    if humanoid then
        humanoid.PlatformStand = false
    end
    
    local animate = character:FindFirstChild("Animate")
    if animate then
        animate.Disabled = false
    end
end)

-- Hover эффекты
FlyToggle.MouseEnter:Connect(function()
    if not FLY_ENABLED then
        FlyToggle.BackgroundColor3 = Color3.fromRGB(70, 70, 70)
    end
end)

FlyToggle.MouseLeave:Connect(function()
    if not FLY_ENABLED then
        FlyToggle.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
    end
end)

-- Обработчик смерти персонажа
Player.CharacterAdded:Connect(function(character)
    local humanoid = character:WaitForChild("Humanoid")
    humanoid.Died:Connect(function()
        if FLY_ENABLED then
            FLY_ENABLED = false
            FlyToggle.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
            FlyToggle.Text = "OFF"
            FlyToggleStroke.Color = Color3.fromRGB(100, 100, 100)
            stopFly()
        end
    end)
end)

-- Очистка при выходе
Player:GetPropertyChangedSignal("Parent"):Connect(function()
    if Player.Parent == nil then
        stopFly()
    end
end)

-- Auto Farm Page
local AutoFarmPage = TabPages["Auto Farm"]

-- Заголовок для Auto Farm страницы
createUIElement("TextLabel", AutoFarmPage, {
    Size = UDim2.new(1, 0, 0, 30),
    BackgroundTransparency = 1,
    Text = "Auto Farm Features",
    TextColor3 = Color3.fromRGB(255, 255, 255),
    Font = Enum.Font.GothamBold,
    TextSize = 18,
    Position = UDim2.new(0, 0, 0, 0)
})

-- Вспомогательные функции для персонажа
local function getCharacter() 
    return Player.Character or Player.CharacterAdded:Wait() 
end

local function getHRP() 
    return getCharacter():WaitForChild("HumanoidRootPart") 
end

-- Обработчики событий
CoinCollected.OnClientEvent:Connect(function(_, current, max)
    if current == max and not States.resetting and States.autoResetEnabled then
        States.resetting = true
        States.bag_full = true
        
        local hrp = getHRP()
        
        if States.start_position then
            local tween = Services.TweenService:Create(
                hrp, 
                TweenInfo.new(2, Enum.EasingStyle.Linear), 
                {CFrame = States.start_position}
            )
            tween:Play()
            tween.Completed:Wait()
        end
        
        task.wait(0.5)
        Player.Character.Humanoid.Health = 0
        Player.CharacterAdded:Wait()
        task.wait(1.5)
        
        States.resetting = false
        States.bag_full = false
    end
end)

RoundStart.OnClientEvent:Connect(function()
    States.farming = true
    if Player.Character and Player.Character:FindFirstChild("HumanoidRootPart") then
        States.start_position = Player.Character.HumanoidRootPart.CFrame
    end
end)

RoundEnd.OnClientEvent:Connect(function()
    States.farming = false
end)

-- Создание переключателей
local function createToggle(parent, name, position, defaultState, callback)
    local Container = createUIElement("Frame", parent, {
        BackgroundColor3 = Color3.fromRGB(20,20,20),
        BackgroundTransparency = 0.1,
        Size = UDim2.new(1, -10, 0, 50),
        Position = position
    })

    createUIElement("UICorner", Container, {CornerRadius = UDim.new(0, 10)})
    createUIElement("UIStroke", Container, {
        Color = Color3.fromRGB(230,57,51),
        Thickness = 1.8
    })

    createUIElement("TextLabel", Container, {
        Size = UDim2.new(0.6, 0, 1, 0),
        Position = UDim2.new(0, 10, 0, 0),
        BackgroundTransparency = 1,
        Font = Enum.Font.GothamBold,
        Text = name,
        TextColor3 = Color3.fromRGB(255, 255, 255),
        TextSize = 16,
        TextXAlignment = Enum.TextXAlignment.Left
    })

    local Toggle = createUIElement("TextButton", Container, {
        Size = UDim2.new(0, 60, 0, 30),
        Position = UDim2.new(1, -70, 0.5, -15),
        BackgroundColor3 = Color3.fromRGB(50, 50, 50),
        BorderSizePixel = 0,
        Text = "OFF",
        TextColor3 = Color3.fromRGB(255, 255, 255),
        Font = Enum.Font.GothamBold,
        TextSize = 12,
        AutoButtonColor = false
    })

    Toggle.MouseButton1Click:Connect(playButtonSound)

    createUIElement("UICorner", Toggle, {CornerRadius = UDim.new(0, 15)})
    local ToggleStroke = createUIElement("UIStroke", Toggle, {
        Color = Color3.fromRGB(100, 100, 100),
        Thickness = 2
    })

    local state = defaultState or false
    
    local function updateToggle()
        if state then
            Toggle.BackgroundColor3 = Color3.fromRGB(230, 57, 51)
            Toggle.Text = "ON"
            ToggleStroke.Color = Color3.fromRGB(200, 50, 47)
        else
            Toggle.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
            Toggle.Text = "OFF"
            ToggleStroke.Color = Color3.fromRGB(100, 100, 100)
        end
    end

    updateToggle()

    Toggle.MouseButton1Click:Connect(function()
        state = not state
        updateToggle()
        if callback then callback(state) end
    end)

    Toggle.MouseEnter:Connect(function()
        if not state then
            Toggle.BackgroundColor3 = Color3.fromRGB(70, 70, 70)
        end
    end)

    Toggle.MouseLeave:Connect(function()
        if not state then
            Toggle.BackgroundColor3 = Color3.fromRGB(50, 50, 50)
        end
    end)

    return Toggle, function() return state end
end

-- Coin Autofarm
local CoinAutofarmToggle, getCoinAutofarmState = createToggle(AutoFarmPage, "Coin Autofarm", UDim2.new(0, 0, 0, 40), false)

-- Auto Reset
local AutoResetToggle, getAutoResetState = createToggle(AutoFarmPage, "Auto Reset", UDim2.new(0, 0, 0, 100), false, function(state)
    States.autoResetEnabled = state
end)

-- Auto Farm логика
local AutoFarmRunning = false
local farmConnection

local function get_nearest_coin()
    local hrp = getHRP()
    local closest, dist = nil, math.huge
    
    for _, m in pairs(Services.Workspace:GetChildren()) do
        if m:FindFirstChild("CoinContainer") then
            for _, coin in pairs(m.CoinContainer:GetChildren()) do
                if coin:IsA("BasePart") and coin:FindFirstChild("TouchInterest") then
                    local d = (hrp.Position - coin.Position).Magnitude
                    if d < dist then 
                        closest, dist = coin, d 
                    end
                end
            end
        end
    end
    return closest, dist
end

local function StartAutoFarm()
    if AutoFarmRunning then return end
    
    AutoFarmRunning = true
    
    farmConnection = task.spawn(function()
        while getCoinAutofarmState() and AutoFarmRunning do
            if States.farming and not States.bag_full then
                local coin, dist = get_nearest_coin()
                if coin then
                    local hrp = getHRP()
                    if dist > 150 then
                        hrp.CFrame = coin.CFrame
                    else
                        local tween = Services.TweenService:Create(hrp, TweenInfo.new(dist / 20, Enum.EasingStyle.Linear), {CFrame = coin.CFrame})
                        tween:Play()
                        
                        repeat 
                            task.wait(0.1) 
                        until not coin:FindFirstChild("TouchInterest") or not States.farming or not getCoinAutofarmState()
                        
                        tween:Cancel()
                    end
                end
            end
            task.wait(0.2)
        end
    end)
end

local function StopAutoFarm()
    AutoFarmRunning = false
    
    if farmConnection then
        task.cancel(farmConnection)
        farmConnection = nil
    end
end

-- Обновление состояния Coin Autofarm
CoinAutofarmToggle:GetPropertyChangedSignal("Text"):Connect(function()
    if getCoinAutofarmState() then
        StartAutoFarm()
    else
        StopAutoFarm()
    end
end)

-- Anti-AFK
Player.Idled:Connect(function()
    Services.VirtualUser:CaptureController()
    Services.VirtualUser:ClickButton2(Vector2.new())
end)

-- Обработчики персонажа
Player.CharacterAdded:Connect(function()
    task.wait(1)
    
    if getCoinAutofarmState() and AutoFarmRunning then
        StopAutoFarm()
        task.wait(0.5)
        if getCoinAutofarmState() then
            StartAutoFarm()
        end
    end
    
    States.resetting = false
    States.bag_full = false
end)

-- Обработчики фокуса окна
Services.UserInputService.WindowFocusReleased:Connect(function()
    if getCoinAutofarmState() then
        StopAutoFarm()
    end
end)

Services.UserInputService.WindowFocused:Connect(function()
    if getCoinAutofarmState() and not AutoFarmRunning then
        StartAutoFarm()
    end
end)

-- Visual Page
local VisualPage = TabPages["Visual"]

-- Заголовок для Visual страницы
createUIElement("TextLabel", VisualPage, {
    Size = UDim2.new(1, 0, 0, 30),
    BackgroundTransparency = 1,
    Text = "Visual Features",
    TextColor3 = Color3.fromRGB(255, 255, 255),
    Font = Enum.Font.GothamBold,
    TextSize = 18,
    Position = UDim2.new(0, 0, 0, 0)
})

-- ESP Highlight
local EspHighlightContainer = createUIElement("Frame", VisualPage, {
    BackgroundColor3 = Color3.fromRGB(20,20,20),
    BackgroundTransparency = 0.1,
    Size = UDim2.new(1, -10, 0, 240),
    Position = UDim2.new(0, 0, 0, 40)
})

createUIElement("UICorner", EspHighlightContainer, {CornerRadius = UDim.new(0, 10)})
createUIElement("UIStroke", EspHighlightContainer, {
    Color = Color3.fromRGB(230,57,51),
    Thickness = 1.8
})

createUIElement("TextLabel", EspHighlightContainer, {
    Size = UDim2.new(1, -20, 0, 30),
    Position = UDim2.new(0, 10, 0, 0),
    BackgroundTransparency = 1,
    Font = Enum.Font.GothamBold,
    Text = "ESP Highlight",
    TextColor3 = Color3.fromRGB(255, 255, 255),
    TextSize = 16,
    TextXAlignment = Enum.TextXAlignment.Left
})

-- Функция создания переключателей ESP
local function createESPToggle(name, position, roleKey)
    local Container = createUIElement("Frame", EspHighlightContainer, {
        BackgroundColor3 = Color3.fromRGB(25,25,25),
        BackgroundTransparency = 0.1,
        Size = UDim2.new(1, -20, 0, 35),
        Position = position
    })

    createUIElement("UICorner", Container, {CornerRadius = UDim.new(0, 8)})
    createUIElement("UIStroke", Container, {
        Color = Color3.fromRGB(60,60,60),
        Thickness = 1
    })

    createUIElement("TextLabel", Container, {
        Size = UDim2.new(0.6, 0, 1, 0),
        Position = UDim2.new(0, 10, 0, 0),
        BackgroundTransparency = 1,
        Font = Enum.Font.GothamBold,
        Text = name,
        TextColor3 = Color3.fromRGB(255, 255, 255),
        TextSize = 14,
        TextXAlignment = Enum.TextXAlignment.Left
    })

    local Toggle = createUIElement("TextButton", Container, {
        Size = UDim2.new(0, 60, 0, 25),
        Position = UDim2.new(1, -70, 0.5, -12.5),
        BackgroundColor3 = StateManagers.ESP[roleKey] and Color3.fromRGB(230, 57, 51) or Color3.fromRGB(50, 50, 50),
        BorderSizePixel = 0,
        Text = StateManagers.ESP[roleKey] and "ON" or "OFF",
        TextColor3 = Color3.fromRGB(255, 255, 255),
        Font = Enum.Font.GothamBold,
        TextSize = 12,
        AutoButtonColor = false
    })

    Toggle.MouseButton1Click:Connect(playButtonSound)

    createUIElement("UICorner", Toggle, {CornerRadius = UDim.new(0, 12)})
    local ToggleStroke = createUIElement("UIStroke", Toggle, {
        Color = StateManagers.ESP[roleKey] and Color3.fromRGB(200, 50, 47) or Color3.fromRGB(100, 100, 100),
        Thickness = 2
    })

    Toggle.MouseButton1Click:Connect(function()
        StateManagers.ESP[roleKey] = not StateManagers.ESP[roleKey]
        Toggle.BackgroundColor3 = StateManagers.ESP[roleKey] and Color3.fromRGB(230, 57, 51) or Color3.fromRGB(50, 50, 50)
        Toggle.Text = StateManagers.ESP[roleKey] and "ON" or "OFF"
        ToggleStroke.Color = StateManagers.ESP[roleKey] and Color3.fromRGB(200, 50, 47) or Color3.fromRGB(100, 100, 100)
        if StateManagers.ESP.Enabled then
            UpdateAllHighlights()
        end
    end)

    return Toggle
end

-- Создание всех ESP переключателей
createESPToggle("Innocent", UDim2.new(0, 0, 0, 40), "Innocent")
createESPToggle("Murder", UDim2.new(0, 0, 0, 80), "Murder")
createESPToggle("Sheriff", UDim2.new(0, 0, 0, 120), "Sheriff")
createESPToggle("Hero", UDim2.new(0, 0, 0, 160), "Hero")

-- Главный переключатель ESP
local MainToggleContainer = createUIElement("Frame", EspHighlightContainer, {
    BackgroundColor3 = Color3.fromRGB(25,25,25),
    BackgroundTransparency = 0.1,
    Size = UDim2.new(1, -20, 0, 35),
    Position = UDim2.new(0, 0, 0, 200)
})

createUIElement("UICorner", MainToggleContainer, {CornerRadius = UDim.new(0, 8)})
createUIElement("UIStroke", MainToggleContainer, {
    Color = Color3.fromRGB(60,60,60),
    Thickness = 1
})

createUIElement("TextLabel", MainToggleContainer, {
    Size = UDim2.new(0.6, 0, 1, 0),
    Position = UDim2.new(0, 10, 0, 0),
    BackgroundTransparency = 1,
    Font = Enum.Font.GothamBold,
    Text = "Enable ESP",
    TextColor3 = Color3.fromRGB(255, 255, 255),
    TextSize = 14,
    TextXAlignment = Enum.TextXAlignment.Left
})

local MainToggle = createUIElement("TextButton", MainToggleContainer, {
    Size = UDim2.new(0, 60, 0, 25),
    Position = UDim2.new(1, -70, 0.5, -12.5),
    BackgroundColor3 = Color3.fromRGB(50, 50, 50),
    BorderSizePixel = 0,
    Text = "OFF",
    TextColor3 = Color3.fromRGB(255, 255, 255),
    Font = Enum.Font.GothamBold,
    TextSize = 12,
    AutoButtonColor = false
})

MainToggle.MouseButton1Click:Connect(playButtonSound)

createUIElement("UICorner", MainToggle, {CornerRadius = UDim.new(0, 12)})
local MainToggleStroke = createUIElement("UIStroke", MainToggle, {
    Color = Color3.fromRGB(100, 100, 100),
    Thickness = 2
})

MainToggle.MouseButton1Click:Connect(function()
    StateManagers.ESP.Enabled = not StateManagers.ESP.Enabled
    MainToggle.BackgroundColor3 = StateManagers.ESP.Enabled and Color3.fromRGB(230, 57, 51) or Color3.fromRGB(50, 50, 50)
    MainToggle.Text = StateManagers.ESP.Enabled and "ON" or "OFF"
    MainToggleStroke.Color = StateManagers.ESP.Enabled and Color3.fromRGB(200, 50, 47) or Color3.fromRGB(100, 100, 100)
    
    if StateManagers.ESP.Enabled then
        -- Запускаем ESP систему
        UpdateAllHighlights()
    else
        -- Очищае

Comments (0)

Log in to leave a comment.

No comments yet.