local CYBERTECH_SAFEZONE_POS = Vector3.new(-345.71, 180.80, -3461.89)
local CYBERTECH_SAFEZONE_RADIUS = 50 -- adjust if needed
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")

local oldGui = playerGui:FindFirstChild("LootControllerGui")
if oldGui then oldGui:Destroy() end

local CURRENT_PLOT = nil
local CURRENT_ISLAND = nil
local TELEPORT_DELAY = 0.08
local AUTO_FARMING = false
local AUTO_LOOP_RUNNING = false
local SPLIT_WAIT_TIME = 10
local MAX_SPLIT_RETRIES = 3

local ISLANDS = {"Basic", "VoidReef", "CyberTech", "RainbowReef", "RadioactiveReef"}
local PLOTS = {"Plot1", "Plot2", "Plot3", "Plot4", "Plot5"}

local BINDS = {
	Collect = Enum.KeyCode.G,
	Home = Enum.KeyCode.F,
	Split = Enum.KeyCode.H,
	AutoFarm = Enum.KeyCode.J,
	SellAll = Enum.KeyCode.K,
}
local BIND_NAMES = {"Collect", "Home", "Split", "AutoFarm", "SellAll"}

local lootFolder = workspace:WaitForChild("ActiveLoot")
local busy = false
local bindListening = nil

local function freezeCharacter()
	local ch = player.Character
	if not ch then return end
	local hrp = ch:FindFirstChild("HumanoidRootPart")
	local hum = ch:FindFirstChild("Humanoid")
	if hrp then
		hrp.Velocity = Vector3.new(0, 0, 0)
		hrp.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
		hrp.AssemblyAngularVelocity = Vector3.new(0, 0, 0)
	end
	if hum then
		hum:ChangeState(Enum.HumanoidStateType.Running)
	end
end

local function safeTp(cf)
	local ch = player.Character
	if not ch then return false end
	local hrp = ch:FindFirstChild("HumanoidRootPart")
	if not hrp then return false end
	hrp.Velocity = Vector3.new(0, 0, 0)
	hrp.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
	hrp.AssemblyAngularVelocity = Vector3.new(0, 0, 0)
	hrp.CFrame = cf
	task.wait()
	hrp.Velocity = Vector3.new(0, 0, 0)
	hrp.AssemblyLinearVelocity = Vector3.new(0, 0, 0)
	hrp.AssemblyAngularVelocity = Vector3.new(0, 0, 0)
	local hum = ch:FindFirstChild("Humanoid")
	if hum then hum:ChangeState(Enum.HumanoidStateType.Running) end
	return true
end

local function waitChar()
	local c = player.Character or player.CharacterAdded:Wait()
	c:WaitForChild("HumanoidRootPart")
	c:WaitForChild("Humanoid")
	return c
end

local function hasHeldItem()
	local ch = player.Character
	if not ch then return false end
	if ch:FindFirstChild("HeldItem") then return true end
	local bs = ch:FindFirstChild("BackStick")
	if bs then
		local cube = bs:FindFirstChild("Cube.004")
		if cube and cube:IsA("BasePart") and cube.Transparency >= 0.99 then
			return true
		end
	end
	return false
end

local function detectPlayerPlot()
	local islands = workspace:FindFirstChild("Islands")
	if not islands then return end
	for _, islandName in ipairs(ISLANDS) do
		local island = islands:FindFirstChild(islandName)
		if not island then continue end
		local plots = island:FindFirstChild("Plots")
		if not plots then continue end
		for _, plot in ipairs(plots:GetChildren()) do
			local ownerId = plot:GetAttribute("OwnerUserId")
			if ownerId and ownerId == player.UserId then
				CURRENT_ISLAND = islandName
				CURRENT_PLOT = plot.Name
				return
			end
		end
	end
	if not CURRENT_ISLAND then CURRENT_ISLAND = "Basic" end
	if not CURRENT_PLOT then CURRENT_PLOT = "Plot1" end
end

detectPlayerPlot()

task.spawn(function()
	while true do
		task.wait(5)
		detectPlayerPlot()
		pcall(function()
			if islandDropdown then islandDropdown.Text = CURRENT_ISLAND end
			if plotDropdown then plotDropdown.Text = CURRENT_PLOT end
			if statusLabel then statusLabel.Text = "🌍 " .. tostring(CURRENT_ISLAND) .. " / " .. tostring(CURRENT_PLOT) end
		end)
	end
end)

--// GUI
local screenGui = Instance.new("ScreenGui", playerGui)
screenGui.Name = "LootControllerGui"
screenGui.ResetOnSpawn = false

local miniButton = Instance.new("TextButton", screenGui)
miniButton.Size = UDim2.new(0, 36, 0, 36)
miniButton.Position = UDim2.new(0.1, 0, 0.15, 0)
miniButton.BackgroundColor3 = Color3.fromRGB(0, 150, 255)
miniButton.Text = "⚡"
miniButton.TextColor3 = Color3.new(1, 1, 1)
miniButton.Font = Enum.Font.GothamBold
miniButton.TextSize = 16
miniButton.Visible = false
miniButton.Active = true
miniButton.Draggable = true
Instance.new("UICorner", miniButton).CornerRadius = UDim.new(0, 8)

local frame = Instance.new("Frame", screenGui)
frame.Name = "MainFrame"
frame.Size = UDim2.new(0, 245, 0, 405)
frame.Position = UDim2.new(0.1, 0, 0.1, 0)
frame.BackgroundColor3 = Color3.fromRGB(18, 18, 28)
frame.Active = true
frame.Draggable = true
frame.BorderSizePixel = 0
Instance.new("UICorner", frame).CornerRadius = UDim.new(0, 8)
local fStroke = Instance.new("UIStroke", frame)
fStroke.Color = Color3.fromRGB(0, 130, 255)
fStroke.Thickness = 1.5

local titleBar = Instance.new("Frame", frame)
titleBar.Size = UDim2.new(1, 0, 0, 26)
titleBar.BackgroundColor3 = Color3.fromRGB(0, 100, 180)
titleBar.BorderSizePixel = 0
Instance.new("UICorner", titleBar).CornerRadius = UDim.new(0, 8)

local title = Instance.new("TextLabel", titleBar)
title.Size = UDim2.new(1, -30, 1, 0)
title.Position = UDim2.new(0, 6, 0, 0)
title.Text = "⚡ Loot Ctrl"
title.BackgroundTransparency = 1
title.TextColor3 = Color3.new(1, 1, 1)
title.Font = Enum.Font.GothamBold
title.TextSize = 11
title.TextXAlignment = Enum.TextXAlignment.Left

local minimizeBtn = Instance.new("TextButton", titleBar)
minimizeBtn.Size = UDim2.new(0, 20, 0, 20)
minimizeBtn.Position = UDim2.new(1, -23, 0, 3)
minimizeBtn.Text = "−"
minimizeBtn.TextColor3 = Color3.new(1, 1, 1)
minimizeBtn.BackgroundColor3 = Color3.fromRGB(180, 40, 40)
minimizeBtn.Font = Enum.Font.GothamBold
minimizeBtn.TextSize = 14
minimizeBtn.BorderSizePixel = 0
Instance.new("UICorner", minimizeBtn).CornerRadius = UDim.new(0, 5)

statusLabel = Instance.new("TextLabel", frame)
statusLabel.Size = UDim2.new(1, -14, 0, 14)
statusLabel.Position = UDim2.new(0, 7, 0, 28)
statusLabel.Text = "🌍 " .. tostring(CURRENT_ISLAND) .. " / " .. tostring(CURRENT_PLOT)
statusLabel.BackgroundTransparency = 1
statusLabel.TextColor3 = Color3.fromRGB(0, 255, 120)
statusLabel.Font = Enum.Font.GothamBold
statusLabel.TextSize = 10
statusLabel.TextXAlignment = Enum.TextXAlignment.Left

local function updateStatus()
	statusLabel.Text = "🌍 " .. tostring(CURRENT_ISLAND) .. " / " .. tostring(CURRENT_PLOT)
end

local function createDropdown(parent, position, options, default, callback)
	local container = Instance.new("Frame", parent)
	container.Position = position
	container.Size = UDim2.new(0, 225, 0, 20)
	container.BackgroundColor3 = Color3.fromRGB(38, 38, 52)
	container.ZIndex = 2
	container.BorderSizePixel = 0
	Instance.new("UICorner", container).CornerRadius = UDim.new(0, 5)

	local button = Instance.new("TextButton", container)
	button.Size = UDim2.new(1, 0, 1, 0)
	button.Text = default or options[1]
	button.TextColor3 = Color3.new(1, 1, 1)
	button.BackgroundTransparency = 1
	button.ZIndex = 3
	button.Font = Enum.Font.Gotham
	button.TextSize = 10

	local listFrame = Instance.new("ScrollingFrame", container)
	listFrame.Position = UDim2.new(0, 0, 1, 2)
	listFrame.Size = UDim2.new(1, 0, 0, math.min(#options * 20, 100))
	listFrame.CanvasSize = UDim2.new(0, 0, 0, #options * 20)
	listFrame.BackgroundColor3 = Color3.fromRGB(28, 28, 42)
	listFrame.Visible = false
	listFrame.ZIndex = 10
	listFrame.BorderSizePixel = 0
	listFrame.ScrollBarThickness = 3
	Instance.new("UICorner", listFrame).CornerRadius = UDim.new(0, 5)

	for i, option in ipairs(options) do
		local opt = Instance.new("TextButton", listFrame)
		opt.Size = UDim2.new(1, 0, 0, 20)
		opt.Position = UDim2.new(0, 0, 0, (i - 1) * 20)
		opt.Text = option
		opt.BackgroundTransparency = 0.6
		opt.BackgroundColor3 = Color3.fromRGB(50, 50, 65)
		opt.TextColor3 = Color3.new(1, 1, 1)
		opt.ZIndex = 11
		opt.Font = Enum.Font.Gotham
		opt.TextSize = 10
		opt.BorderSizePixel = 0
		opt.MouseButton1Click:Connect(function()
			button.Text = option
			listFrame.Visible = false
			callback(option)
		end)
	end
	button.MouseButton1Click:Connect(function()
		listFrame.Visible = not listFrame.Visible
	end)
	return button
end

islandDropdown = createDropdown(frame, UDim2.new(0, 8, 0, 44), ISLANDS, CURRENT_ISLAND, function(v) CURRENT_ISLAND = v updateStatus() end)
plotDropdown = createDropdown(frame, UDim2.new(0, 8, 0, 68), PLOTS, CURRENT_PLOT, function(v) CURRENT_PLOT = v updateStatus() end)

local function makeBtn(parent, pos, size, text, color)
	local btn = Instance.new("TextButton", parent)
	btn.Position = pos
	btn.Size = size
	btn.Text = text
	btn.TextColor3 = Color3.new(1, 1, 1)
	btn.BackgroundColor3 = color
	btn.Font = Enum.Font.GothamBold
	btn.TextSize = 10
	btn.BorderSizePixel = 0
	Instance.new("UICorner", btn).CornerRadius = UDim.new(0, 5)
	return btn
end

local delayL = Instance.new("TextLabel", frame)
delayL.Position = UDim2.new(0, 8, 0, 92)
delayL.Size = UDim2.new(0, 35, 0, 18)
delayL.Text = "Delay"
delayL.BackgroundTransparency = 1
delayL.TextColor3 = Color3.fromRGB(180, 180, 200)
delayL.Font = Enum.Font.Gotham
delayL.TextSize = 9
delayL.TextXAlignment = Enum.TextXAlignment.Left

local delayBox = Instance.new("TextBox", frame)
delayBox.Position = UDim2.new(0, 45, 0, 92)
delayBox.Size = UDim2.new(0, 188, 0, 18)
delayBox.Text = tostring(TELEPORT_DELAY)
delayBox.TextColor3 = Color3.new(1, 1, 1)
delayBox.BackgroundColor3 = Color3.fromRGB(38, 38, 52)
delayBox.Font = Enum.Font.Gotham
delayBox.TextSize = 10
delayBox.BorderSizePixel = 0
Instance.new("UICorner", delayBox).CornerRadius = UDim.new(0, 5)
delayBox.FocusLost:Connect(function()
	local v = tonumber(delayBox.Text)
	if v then TELEPORT_DELAY = v end
end)

local function sep(y)
	local s = Instance.new("Frame", frame)
	s.Position = UDim2.new(0, 8, 0, y)
	s.Size = UDim2.new(0, 225, 0, 1)
	s.BackgroundColor3 = Color3.fromRGB(45, 45, 60)
	s.BorderSizePixel = 0
end

sep(114)

local collectBtn = makeBtn(frame, UDim2.new(0, 8, 0, 118), UDim2.new(0, 110, 0, 26), "🧲 Collect", Color3.fromRGB(0, 120, 60))
local homeBtn = makeBtn(frame, UDim2.new(0, 123, 0, 118), UDim2.new(0, 110, 0, 26), "🏠 Home", Color3.fromRGB(0, 75, 165))
local sellBtn = makeBtn(frame, UDim2.new(0, 8, 0, 148), UDim2.new(0, 110, 0, 26), "💰 Sell All", Color3.fromRGB(170, 120, 0))
local splitBtn = makeBtn(frame, UDim2.new(0, 123, 0, 148), UDim2.new(0, 110, 0, 26), "🪓 Split", Color3.fromRGB(150, 40, 40))

sep(178)

local autoFarmBtn = makeBtn(frame, UDim2.new(0, 8, 0, 182), UDim2.new(0, 225, 0, 28), "🔄 AUTO FARM: OFF", Color3.fromRGB(80, 20, 20))

sep(214)

local bindsT = Instance.new("TextLabel", frame)
bindsT.Position = UDim2.new(0, 8, 0, 217)
bindsT.Size = UDim2.new(0, 225, 0, 12)
bindsT.Text = "⌨️ BINDS (click to rebind)"
bindsT.BackgroundTransparency = 1
bindsT.TextColor3 = Color3.fromRGB(180, 180, 220)
bindsT.Font = Enum.Font.GothamBold
bindsT.TextSize = 9
bindsT.TextXAlignment = Enum.TextXAlignment.Left

local bindButtons = {}
local function getKeyName(kc) return kc and kc.Name or "?" end

local function updateBindTexts()
	for _, n in ipairs(BIND_NAMES) do
		if bindButtons[n] then
			bindButtons[n].Text = n .. " [" .. getKeyName(BINDS[n]) .. "]"
		end
	end
	collectBtn.Text = "🧲 Collect [" .. getKeyName(BINDS.Collect) .. "]"
	homeBtn.Text = "🏠 Home [" .. getKeyName(BINDS.Home) .. "]"
	splitBtn.Text = "🪓 Split [" .. getKeyName(BINDS.Split) .. "]"
	sellBtn.Text = "💰 Sell [" .. getKeyName(BINDS.SellAll) .. "]"
	autoFarmBtn.Text = AUTO_FARMING
		and ("🔄 AUTO: ON [" .. getKeyName(BINDS.AutoFarm) .. "]")
		or ("🔄 AUTO: OFF [" .. getKeyName(BINDS.AutoFarm) .. "]")
end

for i, name in ipairs(BIND_NAMES) do
	local col = (i - 1) % 2
	local row = math.floor((i - 1) / 2)
	local btn = makeBtn(frame, UDim2.new(0, 8 + col * 116, 0, 232 + row * 24), UDim2.new(0, 110, 0, 20), name .. " [" .. getKeyName(BINDS[name]) .. "]", Color3.fromRGB(48, 48, 65))
	btn.TextSize = 9
	btn.Font = Enum.Font.Gotham
	bindButtons[name] = btn
	btn.MouseButton1Click:Connect(function()
		if bindListening then return end
		bindListening = name
		btn.Text = name .. " [...]"
		btn.BackgroundColor3 = Color3.fromRGB(200, 90, 0)
	end)
end

local logLabel = Instance.new("TextLabel", frame)
logLabel.Position = UDim2.new(0, 8, 0, 310)
logLabel.Size = UDim2.new(1, -16, 0, 85)
logLabel.Text = "Ready."
logLabel.BackgroundTransparency = 1
logLabel.TextColor3 = Color3.fromRGB(160, 160, 180)
logLabel.Font = Enum.Font.Gotham
logLabel.TextSize = 9
logLabel.TextWrapped = true
logLabel.TextYAlignment = Enum.TextYAlignment.Top
logLabel.TextXAlignment = Enum.TextXAlignment.Left

local function setLog(msg) logLabel.Text = "📋 " .. msg end

minimizeBtn.MouseButton1Click:Connect(function()
	frame.Visible = false
	miniButton.Visible = true
	miniButton.Position = frame.Position
end)
miniButton.MouseButton1Click:Connect(function()
	miniButton.Visible = false
	frame.Position = miniButton.Position
	frame.Visible = true
end)

--// ЗОНЫ

local function getSafeZone()
	-- Special manual SafeZone for CyberTech
	if CURRENT_ISLAND == "CyberTech" then
		return {
			Position = CYBERTECH_SAFEZONE_POS,
			Size = Vector3.new(CYBERTECH_SAFEZONE_RADIUS, CYBERTECH_SAFEZONE_RADIUS, CYBERTECH_SAFEZONE_RADIUS)
		}
	end
	
	-- Default system for other islands
	local isl = workspace:FindFirstChild("Islands")
	if not isl then return nil end
	
	isl = isl:FindFirstChild(CURRENT_ISLAND)
	if not isl then return nil end
	
	local p = isl:FindFirstChild("Plots")
	if not p then return nil end
	
	p = p:FindFirstChild(CURRENT_PLOT)
	if not p then return nil end
	
	local imp = p:FindFirstChild("Important")
	if not imp then return nil end
	
	return imp:FindFirstChild("SafeZone")
end
local function getSplitZone()
	local isl = workspace:FindFirstChild("Islands")
	if not isl then return nil end
	isl = isl:FindFirstChild(CURRENT_ISLAND)
	if not isl then return nil end
	local p = isl:FindFirstChild("Plots")
	if not p then return nil end
	p = p:FindFirstChild(CURRENT_PLOT)
	if not p then return nil end
	local imp = p:FindFirstChild("Important")
	if not imp then return nil end
	return imp:FindFirstChild("SplitZone")
end

--// СБОР ЛУТА — ТОЛЬКО СВОЙ ПЛОТ + В РАДИУСЕ 800
local function getMatchingLoot()
	local matches = {}
	local ch = player.Character
	if not ch then return matches end
	local hrp = ch:FindFirstChild("HumanoidRootPart")
	if not hrp then return matches end

	for _, m in ipairs(lootFolder:GetChildren()) do
		if m:IsA("Model") and m:GetAttribute("PlotName") == CURRENT_PLOT then
			local ok, pv = pcall(function() return m:GetPivot() end)
			if ok then
				local dist = (pv.Position - hrp.Position).Magnitude
				if dist <= 800 then
					table.insert(matches, m)
				end
			end
		end
	end
	return matches
end

--// HOME = SafeZone (сдача ресурсов), невысоко
local function doHome()
	local sz = getSafeZone()
	if not sz then
		setLog("SafeZone not found!")
		return false
	end
	
	waitChar()

	local targetPosition
	
	if typeof(sz) == "table" then
		targetPosition = sz.Position + Vector3.new(0, 3, 0)
	else
		targetPosition = Vector3.new(
			sz.Position.X,
			sz.Position.Y + sz.Size.Y / 2 + 1,
			sz.Position.Z
		)
	end
	
	local targetCF = CFrame.new(targetPosition)
	safeTp(targetCF)
	task.wait(0.1)
	freezeCharacter()
	setLog("Home (SafeZone).")
	return true
end
--// COLLECT — свой плот, радиус 800
local function doCollect()
	if busy then return false end
	busy = true
	setLog("Collecting...")
	waitChar()

	local loot = getMatchingLoot()
	if #loot == 0 then
		setLog("No loot found.")
		busy = false
		return false
	end

	setLog("Found " .. #loot .. " items...")
	for i, m in ipairs(loot) do
		if not m or not m.Parent then continue end
		local ok, pv = pcall(function() return m:GetPivot() end)
		if ok then
			safeTp(pv + Vector3.new(0, 1, 0))
		end
		task.wait(TELEPORT_DELAY)
		if i % 15 == 0 then setLog("Collecting " .. i .. "/" .. #loot) end
	end

	-- Второй проход
	task.wait(0.3)
	local remaining = getMatchingLoot()
	if #remaining > 0 then
		setLog("Picking up " .. #remaining .. " remaining...")
		for _, m in ipairs(remaining) do
			if not m or not m.Parent then continue end
			local ok, pv = pcall(function() return m:GetPivot() end)
			if ok then
				safeTp(pv + Vector3.new(0, 1, 0))
			end
			task.wait(TELEPORT_DELAY)
		end
	end

	setLog("Collected all.")
	busy = false
	return true
end

local function doCollectAndHome()
	doCollect()
	task.wait(0.2)
	doHome()
end

--// SELL
local function doSell()
	setLog("Selling...")
	local ok = pcall(function()
		ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("SellRequest"):FireServer({Mode = "SellAll"})
	end)
	setLog(ok and "Sold!" or "Sell error!")
	return ok
end

--// EQUIP
local function doEquipStick()
	setLog("Equipping stick...")
	pcall(function()
		ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("HoldSlotRequest"):FireServer(1)
	end)
	task.wait(0.8)
	if hasHeldItem() then return true end
	pcall(function()
		ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("HoldSlotRequest"):FireServer(1)
	end)
	task.wait(0.8)
	return hasHeldItem()
end

--// SPLIT
local function doSplit()
	setLog("Splitting...")
	local sz = getSplitZone()
	if not sz then setLog("SplitZone not found!") return false end
	waitChar()

	local targetCF = CFrame.new(sz.Position.X, sz.Position.Y + sz.Size.Y / 2 + 1, sz.Position.Z)
	safeTp(targetCF)
	task.wait(0.3)
	freezeCharacter()
	task.wait(0.2)

	if not hasHeldItem() then
		if not doEquipStick() then
			setLog("Cannot equip stick!")
			return false
		end
	end

	safeTp(targetCF)
	task.wait(0.15)
	freezeCharacter()

	local ok = pcall(function()
		ReplicatedStorage:WaitForChild("Remotes"):WaitForChild("SplitRequest"):FireServer(1, true)
	end)
	setLog(ok and "Split done!" or "Split error!")
	return ok
end

--// АВТОФАРМ
-- Home (сдать) → SplitZone → Split → Ждём лут → Collect → Home (сдать) → Sell → повтор
local function autoFarmLoop()
	if AUTO_LOOP_RUNNING then return end
	AUTO_LOOP_RUNNING = true
	setLog("Auto Farm STARTED!")
	autoFarmBtn.BackgroundColor3 = Color3.fromRGB(0, 140, 50)
	updateBindTexts()

	while AUTO_FARMING do
		pcall(detectPlayerPlot)
		updateStatus()
		pcall(function()
			islandDropdown.Text = CURRENT_ISLAND or "?"
			plotDropdown.Text = CURRENT_PLOT or "?"
		end)

		-- 1) Home — сдать что есть
		setLog("[Auto] Home (deliver)...")
		doHome()
		task.wait(0.5)
		if not AUTO_FARMING then break end

		-- 2) Split (с ретраями)
		local splitOk = false
		for attempt = 1, MAX_SPLIT_RETRIES do
			if not AUTO_FARMING then break end
			setLog("[Auto] Split attempt " .. attempt .. "/" .. MAX_SPLIT_RETRIES)
			splitOk = doSplit()
			if splitOk then break end
			task.wait(0.5)
		end
		if not AUTO_FARMING then break end

		-- 3) Ждём лут
		setLog("[Auto] Waiting for loot...")
		local waitTime = 0
		local lootFound = false
		while waitTime < SPLIT_WAIT_TIME and AUTO_FARMING do
			local loot = getMatchingLoot()
			if #loot > 0 then
				setLog("[Auto] Loot: " .. #loot .. " items!")
				lootFound = true
				task.wait(0.6)
				break
			end
			task.wait(0.3)
			waitTime = waitTime + 0.3
		end
		if not AUTO_FARMING then break end

		-- Если лута нет — повтор сплита
		if not lootFound then
			setLog("[Auto] No loot, retrying...")
			continue
		end

		-- 4) Collect
		setLog("[Auto] Collecting...")
		doCollect()
		task.wait(0.3)
		if not AUTO_FARMING then break end

		-- 5) Home — сдать собранное
		setLog("[Auto] Home (deliver)...")
		doHome()
		task.wait(0.5)
		if not AUTO_FARMING then break end

		-- 6) Sell
		setLog("[Auto] Selling...")
		doSell()
		task.wait(0.3)
		if not AUTO_FARMING then break end

		-- 7) Проверка остатков
		local leftover = getMatchingLoot()
		if #leftover > 0 then
			setLog("[Auto] Leftover: " .. #leftover .. ", collecting...")
			doCollect()
			task.wait(0.2)
			doHome()
			task.wait(0.3)
			doSell()
			task.wait(0.2)
		end
		if not AUTO_FARMING then break end

		setLog("[Auto] Cycle done!")
		task.wait(0.2)
	end

	setLog("Auto Farm STOPPED.")
	autoFarmBtn.BackgroundColor3 = Color3.fromRGB(80, 20, 20)
	AUTO_LOOP_RUNNING = false
	updateBindTexts()
end

--// КНОПКИ
collectBtn.MouseButton1Click:Connect(function()
	if AUTO_FARMING then return end
	task.spawn(doCollectAndHome)
end)
homeBtn.MouseButton1Click:Connect(function()
	if AUTO_FARMING then return end
	doHome()
end)
sellBtn.MouseButton1Click:Connect(function()
	if AUTO_FARMING then return end
	doSell()
end)
splitBtn.MouseButton1Click:Connect(function()
	if AUTO_FARMING then return end
	task.spawn(doSplit)
end)
autoFarmBtn.MouseButton1Click:Connect(function()
	AUTO_FARMING = not AUTO_FARMING
	if AUTO_FARMING then task.spawn(autoFarmLoop) else setLog("Stopping...") end
	updateBindTexts()
end)

--// КЛАВИШИ
UserInputService.InputBegan:Connect(function(input, gp)
	if gp then return end
	if not input.KeyCode or input.KeyCode == Enum.KeyCode.Unknown then return end

	if bindListening then
		BINDS[bindListening] = input.KeyCode
		local b = bindButtons[bindListening]
		if b then b.BackgroundColor3 = Color3.fromRGB(48, 48, 65) end
		setLog("'" .. bindListening .. "' → [" .. input.KeyCode.Name .. "]")
		bindListening = nil
		updateBindTexts()
		return
	end

	if input.KeyCode == BINDS.AutoFarm then
		AUTO_FARMING = not AUTO_FARMING
		if AUTO_FARMING then task.spawn(autoFarmLoop) else setLog("Stopping...") end
		updateBindTexts()
		return
	end

	if AUTO_FARMING then return end

	if input.KeyCode == BINDS.Collect then
		task.spawn(doCollectAndHome)
	elseif input.KeyCode == BINDS.Home then
		doHome()
	elseif input.KeyCode == BINDS.Split then
		task.spawn(doSplit)
	elseif input.KeyCode == BINDS.SellAll then
		doSell()
	end
end)
local function isInCyberTechSafeZone()
	if CURRENT_ISLAND ~= "CyberTech" then return false end
	
	local ch = player.Character
	if not ch then return false end
	
	local hrp = ch:FindFirstChild("HumanoidRootPart")
	if not hrp then return false end
	
	local distance = (hrp.Position - CYBERTECH_SAFEZONE_POS).Magnitude
	return distance <= CYBERTECH_SAFEZONE_RADIUS
end
updateBindTexts()
task.spawn(function()
	task.wait(1)
	detectPlayerPlot()
	pcall(function()
		islandDropdown.Text = CURRENT_ISLAND or "?"
		plotDropdown.Text = CURRENT_PLOT or "?"
	end)
	updateStatus()
	updateBindTexts()
	setLog("Detected: " .. tostring(CURRENT_ISLAND) .. "/" .. tostring(CURRENT_PLOT))
end)
[🌊] Split The Sea Auto Farm – Auto Collect, Split, Sell & GUI
Mobile Friendly
737 views
7 months ago

Auto Farm – Auto Collect, Split, Sell & GUI

WORKING
Free

Description

Best Split the Sea auto farm script with auto collect, split, sell, and teleport features. Includes a modern GUI, customizable hotkeys, and a fully automated farming system for fast and efficient gameplay.

Features

  • Auto Farm
  • Auto Collect
  • Auto Split
  • Instant Sell All
  • Teleport

Related Scripts