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


-- Services
local Players = game:GetService("Players")
local PathfindingService = game:GetService("PathfindingService")
local UserInputService = game:GetService("UserInputService")
local LocalPlayer = Players.LocalPlayer

-- Variables
local GIVE_PER_RESET = 5000
local isRunning = false
local selectedPlayer = nil
local STOP_DISTANCE = 4 -- Расстояние (в studs), на которое нужно подойти

-- UI Creation
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "AutoWalkTransferGui"
ScreenGui.ResetOnSpawn = false
ScreenGui.Parent = game:GetService("CoreGui")

local MainFrame = Instance.new("Frame")
MainFrame.Name = "MainFrame"
MainFrame.Size = UDim2.new(0, 260, 0, 360)
MainFrame.Position = UDim2.new(0.5, -130, 0.3, 0)
MainFrame.BackgroundColor3 = Color3.fromRGB(25, 25, 30)
MainFrame.BorderSizePixel = 0
MainFrame.Active = true
MainFrame.Parent = ScreenGui

local UICorner = Instance.new("UICorner", MainFrame)
UICorner.CornerRadius = UDim.new(0, 10)

-- Dragging Logic (Touch / PC)
local dragging, dragInput, dragStart, startPos
MainFrame.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
        dragging = true
        dragStart = input.Position
        startPos = MainFrame.Position
        
        input.Changed:Connect(function()
            if input.UserInputState == Enum.UserInputState.End then
                dragging = false
            end
        end)
    end
end)

MainFrame.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 input == dragInput and dragging then
        local delta = input.Position - dragStart
        MainFrame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
    end
end)

-- Title
local Title = Instance.new("TextLabel")
Title.Size = UDim2.new(1, 0, 0, 35)
Title.BackgroundTransparency = 1
Title.Text = "Auto Walk & Reset (5k/Reset)"
Title.TextColor3 = Color3.fromRGB(255, 255, 255)
Title.Font = Enum.Font.GothamBold
Title.TextSize = 13
Title.Parent = MainFrame

-- Player Scroll List
local ScrollList = Instance.new("ScrollingFrame")
ScrollList.Size = UDim2.new(0.9, 0, 0, 140)
ScrollList.Position = UDim2.new(0.05, 0, 0.12, 0)
ScrollList.BackgroundColor3 = Color3.fromRGB(35, 35, 42)
ScrollList.BorderSizePixel = 0
ScrollList.ScrollBarThickness = 4
ScrollList.Parent = MainFrame
Instance.new("UICorner", ScrollList).CornerRadius = UDim.new(0, 6)

local UIListLayout = Instance.new("UIListLayout", ScrollList)
UIListLayout.SortOrder = Enum.SortOrder.LayoutOrder
UIListLayout.Padding = UDim.new(0, 4)

local function updatePlayerList()
    for _, child in pairs(ScrollList:GetChildren()) do
        if child:IsA("TextButton") then child:Destroy() end
    end
    
    for _, plr in pairs(Players:GetPlayers()) do
        if plr ~= LocalPlayer then
            local btn = Instance.new("TextButton")
            btn.Size = UDim2.new(1, -8, 0, 28)
            btn.Position = UDim2.new(0, 4, 0, 0)
            btn.BackgroundColor3 = (selectedPlayer == plr) and Color3.fromRGB(0, 170, 100) or Color3.fromRGB(45, 45, 55)
            btn.TextColor3 = Color3.fromRGB(255, 255, 255)
            btn.Font = Enum.Font.Gotham
            btn.TextSize = 12
            btn.Text = plr.DisplayName .. " (@" .. plr.Name .. ")"
            btn.Parent = ScrollList
            Instance.new("UICorner", btn).CornerRadius = UDim.new(0, 4)
            
            btn.MouseButton1Click:Connect(function()
                selectedPlayer = plr
                updatePlayerList()
            end)
        end
    end
    ScrollList.CanvasSize = UDim2.new(0, 0, 0, UIListLayout.AbsoluteContentSize.Y + 10)
end

Players.PlayerAdded:Connect(updatePlayerList)
Players.PlayerRemoving:Connect(updatePlayerList)
updatePlayerList()

-- Amount Input
local AmountBox = Instance.new("TextBox")
AmountBox.Size = UDim2.new(0.9, 0, 0, 32)
AmountBox.Position = UDim2.new(0.05, 0, 0.55, 0)
AmountBox.PlaceholderText = "Введите сумму (напр. 1000000)"
AmountBox.Text = ""
AmountBox.TextColor3 = Color3.fromRGB(255, 255, 255)
AmountBox.BackgroundColor3 = Color3.fromRGB(35, 35, 42)
AmountBox.BorderSizePixel = 0
AmountBox.Font = Enum.Font.Gotham
AmountBox.TextSize = 12
AmountBox.Parent = MainFrame
Instance.new("UICorner", AmountBox).CornerRadius = UDim.new(0, 6)

-- Status Info
local StatusLabel = Instance.new("TextLabel")
StatusLabel.Size = UDim2.new(0.9, 0, 0, 30)
StatusLabel.Position = UDim2.new(0.05, 0, 0.66, 0)
StatusLabel.BackgroundTransparency = 1
StatusLabel.Text = "Ресетов нужно: 0 | Осталось: 0"
StatusLabel.TextColor3 = Color3.fromRGB(180, 180, 180)
StatusLabel.Font = Enum.Font.Gotham
StatusLabel.TextSize = 11
StatusLabel.TextWrapped = true
StatusLabel.Parent = MainFrame

-- Action Button
local ActionBtn = Instance.new("TextButton")
ActionBtn.Size = UDim2.new(0.9, 0, 0, 36)
ActionBtn.Position = UDim2.new(0.05, 0, 0.78, 0)
ActionBtn.BackgroundColor3 = Color3.fromRGB(0, 150, 255)
ActionBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
ActionBtn.Font = Enum.Font.GothamBold
ActionBtn.TextSize = 13
ActionBtn.Text = "Подтвердить и начать"
ActionBtn.Parent = MainFrame
Instance.new("UICorner", ActionBtn).CornerRadius = UDim.new(0, 6)

-- Функция ходьбы к игроку с обходом препятствий
local function walkToTarget(targetRoot, hum, myRoot)
    local path = PathfindingService:CreatePath({
        AgentRadius = 2,
        AgentHeight = 5,
        AgentCanJump = true
    })
    
    while isRunning and hum.Health > 0 do
        if not targetRoot or not targetRoot.Parent then break end
        
        local distance = (myRoot.Position - targetRoot.Position).Magnitude
        if distance <= STOP_DISTANCE then
            return true
        end

        local success, _ = pcall(function()
            path:ComputeAsyncPath(myRoot.Position, targetRoot.Position)
        end)

        if success and path.Status == Enum.PathStatus.Success then
            local waypoints = path:GetWaypoints()
            for i = 2, math.min(#waypoints, 4) do
                if not isRunning or hum.Health <= 0 then break end
                
                local currentDist = (myRoot.Position - targetRoot.Position).Magnitude
                if currentDist <= STOP_DISTANCE then return true end

                if waypoints[i].Action == Enum.PathWayPointAction.Jump then
                    hum.Jump = true
                end
                
                hum:MoveTo(waypoints[i].Position)
                hum.MoveToFinished:Wait(0.5)
            end
        else
            -- Прямой ход при ошибке построения пути
            hum:MoveTo(targetRoot.Position)
            task.wait(0.2)
        end
        
        task.wait(0.05)
    end
    return false
end

-- Основной цикл
local function startFarming()
    local totalAmount = tonumber(AmountBox.Text)
    if not totalAmount or totalAmount <= 0 then
        StatusLabel.Text = "Ошибка: укажите корректную сумму"
        return
    end
    
    if not selectedPlayer or not selectedPlayer.Parent then
        StatusLabel.Text = "Ошибка: выберите игрока из списка"
        return
    end

    local totalResets = math.ceil(totalAmount / GIVE_PER_RESET)
    isRunning = true
    ActionBtn.Text = "Остановить"
    ActionBtn.BackgroundColor3 = Color3.fromRGB(200, 50, 50)

    task.spawn(function()
        for i = 1, totalResets do
            if not isRunning then break end
            
            StatusLabel.Text = string.format("Иду к цели... [%d / %d]", i, totalResets)
            
            local char = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
            local root = char:WaitForChild("HumanoidRootPart", 10)
            local hum = char:WaitForChild("Humanoid", 10)
            
            local targetChar = selectedPlayer.Character
            local targetRoot = targetChar and targetChar:FindFirstChild("HumanoidRootPart")
            
            if root and targetRoot and hum and hum.Health > 0 then
                -- Персонаж идет пешком
                local arrived = walkToTarget(targetRoot, hum, root)
                
                if arrived and isRunning then
                    StatusLabel.Text = string.format("Подошел! Сброс... [%d / %d]", i, totalResets)
                    task.wait(0.2)
                    hum.Health = 0
                end
            end
            
            if not isRunning then break end
            
            -- Ожидание возрождения
            LocalPlayer.CharacterAdded:Wait()
            task.wait(0.6)
        end
        
        isRunning = false
        ActionBtn.Text = "Подтвердить и начать"
        ActionBtn.BackgroundColor3 = Color3.fromRGB(0, 150, 255)
        StatusLabel.Text = "Готово! Все циклы завершены."
    end)
end

ActionBtn.MouseButton1Click:Connect(function()
    if isRunning then
        isRunning = false
        ActionBtn.Text = "Подтвердить и начать"
        ActionBtn.BackgroundColor3 = Color3.fromRGB(0, 150, 255)
        StatusLabel.Text = "Остановлено"
    else
        startFarming()
    end
end)