CCCPaste

Auto fish+chest

getgenv().Enabled = false

local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local GuiService = game:GetService("GuiService")
local VIM = game:GetService("VirtualInputManager")

local MaxChest = 500
local FishButton = nil
local isFishing = false

---------------------------------------------------------
-- PRESS ENTER USING UI NAVIGATION
---------------------------------------------------------
local function PressEnter()
    VIM:SendKeyEvent(true, Enum.KeyCode.Return, false, game)
    VIM:SendKeyEvent(false, Enum.KeyCode.Return, false, game)
end

---------------------------------------------------------
-- OPEN CHEST (YOUR ORIGINAL METHOD)
---------------------------------------------------------
local function OpenChest(chestName)
    if chestName ~= "Common Chest" and chestName ~= "Rare Chest" then return end

    local inventory = plr:FindFirstChild("Inventory")
    if not inventory then return end

    local chestVal = inventory:FindFirstChild(chestName)
    if not chestVal or chestVal.Value < MaxChest then return end

    local playerGui = plr:WaitForChild("PlayerGui")
    local storageFrame = playerGui:FindFirstChild("Button") and playerGui.Button:FindFirstChild("Storage_Frame")
    if not storageFrame then return end

    storageFrame.Visible = true
    task.wait()

    local materialFrame = storageFrame:FindFirstChild("Material_Frame")
    local chestButton = materialFrame and materialFrame:FindFirstChild(chestName)
    if not chestButton then
        storageFrame.Visible = false
        return
    end

    GuiService.SelectedObject = chestButton
    task.wait()
    PressEnter()
    task.wait()

    local confirmGui = playerGui.Button:FindFirstChild("Confirm")
    if confirmGui then
        local event = confirmGui:FindFirstChild("Event")
        if event then
            event:FireServer(chestVal.Value)
        end

        local acceptBtn = confirmGui.Accept and confirmGui.Accept:FindFirstChild("Button")
        if acceptBtn then
            GuiService.SelectedObject = acceptBtn
            task.wait()
            PressEnter()
        end
    end

    task.wait()
    VIM:SendKeyEvent(true, Enum.KeyCode.BackSlash, false, game)
    VIM:SendKeyEvent(false, Enum.KeyCode.BackSlash, false, game)
    storageFrame.Visible = false
end

---------------------------------------------------------
-- ULTRA FAST FISHING (UI-NAV SPAM)
---------------------------------------------------------
local function TriggerFishing()
    if not FishButton then return end
    if isFishing then return end
    isFishing = true

    GuiService.SelectedObject = FishButton

    for i = 1, 15 do
        if not getgenv().Enabled then break end

        -- stop if chest full
        local inv = plr:FindFirstChild("Inventory")
        if inv then
            local c = inv:FindFirstChild("Common Chest")
            local r = inv:FindFirstChild("Rare Chest")

            if (c and c.Value >= MaxChest) or (r and r.Value >= MaxChest) then
                isFishing = false
                return
            end
        end

        PressEnter()
    end

    isFishing = false
end

---------------------------------------------------------
-- UI CREATION (UPDATED)
---------------------------------------------------------
local gui = Instance.new("ScreenGui", plr.PlayerGui)
gui.ResetOnSpawn = false

local frame = Instance.new("Frame", gui)
frame.Size = UDim2.new(0, 120, 0, 180)
frame.Position = UDim2.new(0.5, -60, 0.5, -90)
frame.BackgroundColor3 = Color3.fromRGB(125, 255, 255)
frame.Active = true
frame.Draggable = true

local toggleButton = Instance.new("TextButton", frame)
toggleButton.Size = UDim2.new(0, 100, 0, 30)
toggleButton.Position = UDim2.new(0.5, 0, 0.55, 0)
toggleButton.AnchorPoint = Vector2.new(0.5, 0)
toggleButton.TextScaled = true
toggleButton.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
toggleButton.Text = "เปิด"

local minimizeButton = Instance.new("TextButton", frame)
minimizeButton.Size = UDim2.new(0, 100, 0, 30)
minimizeButton.Position = UDim2.new(0.5, 0, 0.8, 0)
minimizeButton.AnchorPoint = Vector2.new(0.5, 0)
minimizeButton.TextScaled = true
minimizeButton.BackgroundColor3 = Color3.fromRGB(255, 0, 0)
minimizeButton.Text = "ย่อเมนู"

-- UPDATED: GREEN, SMALL & DRAGGABLE OPEN BUTTON
local openButton = Instance.new("TextButton", gui)
openButton.Size = UDim2.new(0, 70, 0, 35)
openButton.Position = UDim2.new(0.5, -35, 0.5, -20)
openButton.BackgroundColor3 = Color3.fromRGB(0, 255, 0)
openButton.Text = "เปิด"
openButton.TextScaled = true
openButton.Visible = false
openButton.Active = true
openButton.Draggable = true

---------------------------------------------------------
-- DRAG SUPPORT (FOR MOBILE)
---------------------------------------------------------
local function enableDragging(guiElement)
    local dragging, mousePos, framePos

    guiElement.InputBegan:Connect(function(input)
        if input.UserInputType == Enum.UserInputType.MouseButton1
        or input.UserInputType == Enum.UserInputType.Touch then

            dragging = true
            mousePos = input.Position
            framePos = guiElement.Position

            input.Changed:Connect(function()
                if input.UserInputState == Enum.UserInputState.End then
                    dragging = false
                end
            end)
        end
    end)

    guiElement.InputChanged:Connect(function(input)
        if dragging and 
        (input.UserInputType == Enum.UserInputType.MouseMovement 
        or input.UserInputType == Enum.UserInputType.Touch) then
            
            local delta = input.Position - mousePos
            guiElement.Position = UDim2.new(
                framePos.X.Scale, framePos.X.Offset + delta.X,
                framePos.Y.Scale, framePos.Y.Offset + delta.Y
            )
        end
    end)
end

enableDragging(frame)
enableDragging(openButton)

---------------------------------------------------------
-- FIND FISH BUTTON
---------------------------------------------------------
plr.PlayerGui.HUD.DescendantAdded:Connect(function(v)
    if v.Name == "Button" and v.Parent.Name == "Fishing" then
        FishButton = v
        if getgenv().Enabled then
            task.spawn(TriggerFishing)
        end
    end
end)

---------------------------------------------------------
-- MAIN LOOP
---------------------------------------------------------
task.spawn(function()
    while true do
        task.wait()

        if getgenv().Enabled and FishButton then
            local inv = plr:FindFirstChild("Inventory")
            if inv then
                local common = inv:FindFirstChild("Common Chest")
                local rare = inv:FindFirstChild("Rare Chest")

                if common and common.Value >= MaxChest then
                    OpenChest("Common Chest")
                elseif rare and rare.Value >= MaxChest then
                    OpenChest("Rare Chest")
                else
                    task.spawn(TriggerFishing)
                end
            end
        end
    end
end)

---------------------------------------------------------
-- UI BUTTONS
---------------------------------------------------------
toggleButton.MouseButton1Click:Connect(function()
    getgenv().Enabled = not getgenv().Enabled
    toggleButton.Text = getgenv().Enabled and "ปิด" or "เปิด"

    if not getgenv().Enabled then
        GuiService.SelectedObject = nil
    end
end)

minimizeButton.MouseButton1Click:Connect(function()
    frame.Visible = false
    openButton.Visible = true
end)

openButton.MouseButton1Click:Connect(function()
    frame.Visible = true
    openButton.Visible = false
end)