local genv = getgenv()
local GEN = (genv.__CoopKingGen or 0) + 1
genv.__CoopKingGen = GEN
local function destroyOldWindows()
local rg = game:GetService("CoreGui"):FindFirstChild("RobloxGui")
if not rg then return end
for _, c in rg:GetChildren() do
if c:IsA("ScreenGui") and string.len(c.Name) == 36 then
local txt = ""
for _, d in c:GetDescendants() do
if d:IsA("TextLabel") and d.Text then txt = txt .. d.Text end
if #txt > 64 then break end
end
if string.match(txt, "Coop King") then pcall(function() c:Destroy() end) end
end
end
end
destroyOldWindows()
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Paper = require(ReplicatedStorage.Paper)
local STATS = Paper.Stats
local Chickens = require(ReplicatedStorage.Modules.Shared.Chickens)
local NET = Paper.Network
pcall(STATS.LoadedAsync)
local okR, Rayfield = pcall(function() return loadstring(game:HttpGet("https://sirius.menu/gen2"))() end)
if not okR then print("RAYFIELD_FAIL "..tostring(Rayfield)); return end
local Window = Rayfield:CreateWindow({
name = "Coop King",
subtitle = "Chicken Farm Hub v3",
configuration = { autoSave = true, autoLoad = true, fileName = "CoopKing" }
})
Window:Notify({ title = "Coop King", content = "Hub loaded." })
local mainTab = Window:CreateTab({ name = "Main" })
local statTab = Window:CreateTab({ name = "Stats" })
local rebTab = Window:CreateTab({ name = "Rebirth" })
local interval = mainTab:CreateSlider({ name = "Loop interval (s)", range = { 0.5, 3 }, increment = 0.1, value = 1, suffix = "s" })
local keepCash = mainTab:CreateSlider({ name = "Keep cash reserve", range = { 0, 50000 }, increment = 100, value = 500, suffix = "$" })
local master = mainTab:CreateToggle({ name = "Enable farm loop", flag = "master", value = true })
local autoCash = mainTab:CreateToggle({ name = "Auto collect cash", flag = "autoCash", value = true })
local autoBuy = mainTab:CreateToggle({ name = "Auto buy chickens", flag = "autoBuy", value = true })
local buySlider = mainTab:CreateSlider({ name = "Max chickens per buy", range = { 1, 100 }, increment = 1, value = 25 })
local autoMerge = mainTab:CreateToggle({ name = "Auto merge chickens", flag = "autoMerge", value = true })
local autoEggs = mainTab:CreateToggle({ name = "Auto collect eggs", flag = "autoEggs", value = true })
local autoDeposit = mainTab:CreateToggle({ name = "Auto deposit eggs to market", flag = "autoDeposit", value = true })
local autoProcess = mainTab:CreateToggle({ name = "Auto upgrade processing", flag = "autoProcess", value = true })
local autoTier = mainTab:CreateToggle({ name = "Auto upgrade buy tier", flag = "autoTier", value = true })
local autoLucky = mainTab:CreateToggle({ name = "Auto lucky blocks", flag = "autoLucky", value = false })
local autoRebirth = rebTab:CreateToggle({ name = "Auto rebirth", flag = "autoRebirth", value = true })
rebTab:CreateButton({ name = "Rebirth now", callback = function() NET.InvokeServer("Rebirth") end })
rebTab:CreateButton({ name = "Rejoin server", callback = function() NET.InvokeServer("Rejoin") end })
local function mkStat(t, name, prefix)
return t:CreateStat({ name = name, prefix = prefix, value = 0, numberEasing = false })
end
local statCash = mkStat(statTab, "Cash", "$")
local statTotal = mkStat(statTab, "Chickens", "")
local statEggs = mkStat(statTab, "Eggs processing", "")
local statCollect = mkStat(statTab, "Cash waiting", "$")
local statProc = mkStat(statTab, "Processing level", "")
local statTier = mkStat(statTab, "Buy tier", "")
local statReb = mkStat(statTab, "Rebirths", "")
local rebReqStat = mkStat(rebTab, "Rebirth requirement", "$")
genv.__CoopKingStats = { statCash, statTotal, statEggs, statCollect, statProc, statTier, statReb, rebReqStat }
local function refreshStats()
local function GV(key) local ok, v = pcall(STATS.GetValue, key); return ok and v or 0 end
local s = { statCash, statTotal, statEggs, statCollect, statProc, statTier, statReb, rebReqStat }
local v = { GV("Cash"), GV("TotalChickens"), GV("EggsProcessing"), GV("CashCollect"), GV("ProcessingLevel"), GV("BuyTierLevel"), GV("Rebirth"), Chickens.GetRebirthReq((GV("Rebirth")) + 1) or 0 }
for i = 1, #s do
pcall(function() s[i]:Set(v[i]) end)
end
end
task.spawn(function()
pcall(STATS.LoadedAsync)
task.wait(1.2)
refreshStats()
while true do
task.wait(0.4)
if getgenv().__CoopKingGen ~= GEN then break end
refreshStats()
end
end)
print("HUB v3 ready gen="..GEN)
local last = { cash = 0, buy = 0, merge = 0, eggs = 0, depos = 0, process = 0, tier = 0, rebirth = 0, lucky = 0 }
local function nowx() return os.clock() end
local function elapsed(k) return nowx() - last[k] end
local function alive() return genv.__CoopKingGen == GEN end
local function GV(key) local ok, v = pcall(STATS.GetValue, key); return ok and v or 0 end
local function Invoke(name, ...) local ok, a, b = pcall(NET.InvokeServer, name, ...); if not ok then return nil end; return a, b end
-- Egg + Lucky block pull worker
task.spawn(function()
pcall(STATS.LoadedAsync)
local function getRoot()
local char = game.Players.LocalPlayer.Character
return char and char:FindFirstChild("HumanoidRootPart")
end
while alive() do
task.wait(0.6)
if not alive() then break end
if not (master.value and autoEggs.value) then continue end
local root = getRoot()
if not root or not root.Parent then continue end
local eggHolder = workspace:FindFirstChild("Eggs")
if not eggHolder then continue end
local pulled = 0
for _, e in eggHolder:GetChildren() do
if e.Parent then
if e:GetAttribute("Tier") then
e:PivotTo(CFrame.new(root.Position + Vector3.new(0, 3, 0)))
pulled = pulled + 1
elseif e:GetAttribute("LuckyBlock") and autoLucky.value then
local equipped = GV("EquippedLuckyBlock")
if equipped == 0 then
e:PivotTo(CFrame.new(root.Position + Vector3.new(0, 3, 0)))
pulled = pulled + 1
end
end
end
end
if pulled > 0 then
local t = genv.__CoopKingPullTotal or 0
genv.__CoopKingPullTotal = t + pulled
if t % 20 == 0 then print("EGG_PULL "..(t + pulled).." total") end
end
end
end)
local BATTERIES = { 100, 25, 5, 1 }
local function buyChickens(cash)
local total = GV("TotalChickens")
local tier = GV("BuyTierLevel")
local cap = buySlider.value
local spendable = cash
if cash > keepCash.value then spendable = cash - keepCash.value end
for _, amt in BATTERIES do
if amt > cap then continue end
local cost = Chickens.GetBuyChickenCost(total, tier, amt)
if cost and spendable >= cost then
local ok = Invoke("Buy Chickens", amt)
if ok then return true end
end
end
if total == 0 then
local cost = Chickens.GetBuyChickenCost(0, tier, 1)
if cost and cash >= cost then
local ok = Invoke("Buy Chickens", 1)
if ok then return true end
end
end
return false
end
-- Main farm loop
task.spawn(function()
pcall(STATS.LoadedAsync)
while alive() do
task.wait(interval.value)
if not alive() then break end
local cash = GV("Cash")
local spendable = cash
if cash > keepCash.value then spendable = cash - keepCash.value end
if master.value then
if autoDeposit.value and elapsed("depos") > 2 then
local ok, err = Invoke("Deposit Eggs")
if not ok and err then print("DEPOSIT err "..tostring(err)) end
last.depos = nowx()
end
if autoCash.value and elapsed("cash") > 1.2 then
if GV("CashCollect") > 0 then
local ok, amt = Invoke("Collect Cash")
if not ok then print("COLLECT_CASH err") end
end
last.cash = nowx()
end
if autoBuy.value and elapsed("buy") > 1.5 then
local ok, err = pcall(buyChickens, cash)
if not ok then print("BUY err "..tostring(err)) end
last.buy = nowx()
end
if autoMerge.value and elapsed("merge") > 3 then
local ok, res = Invoke("Merge Chickens")
if not ok and res then print("MERGE err "..tostring(res)) end
last.merge = nowx()
end
if autoProcess.value and elapsed("process") > 2 then
local procLevel = GV("ProcessingLevel")
local cost = Chickens.GetProcessCost(procLevel)
if cost and spendable >= cost then
local ok, res = Invoke("Upgrade Process Level")
if not ok and res then print("UP_PROC err "..tostring(res)) end
end
last.process = nowx()
end
if autoTier.value and elapsed("tier") > 3 then
local tier = GV("BuyTierLevel")
local cost = Chickens.GetUpgTierCost(tier)
if cost and GV("TotalChickens") >= Chickens.GetUpgTierReq(tier) and spendable >= cost then
local ok, res = Invoke("Upgrade Buy Tier Level")
if not ok and res then print("UP_TIER err "..tostring(res)) end
end
last.tier = nowx()
end
if autoLucky.value and not genv.__CoopKingPauseLucky and elapsed("lucky") > 5 then
local equipped = GV("EquippedLuckyBlock")
if equipped and equipped ~= 0 then
local isFree = Paper.Stats.GetValue("IsCurrentLuckyBlockFree")
local cost = Chickens.GetLuckyBlockCost(GV("TotalChickens"), equipped, GV("Rebirth"))
local canAfford = (isFree == true) or (cost and spendable >= cost)
if canAfford then
local ok, res = Invoke("Open Lucky Block")
if ok then
Paper.Network.FireServer("Claim Opened Chicken")
end
end
end
last.lucky = nowx()
end
end
if autoRebirth.value and elapsed("rebirth") > 6 then
local reb = GV("Rebirth")
local req = Chickens.GetRebirthReq(reb + 1)
if req and cash >= req then
local ok, err = Invoke("Rebirth")
if ok then print("AUTO_REBIRTH -> "..(reb+1))
elseif err then print("REBIRTH_ERR "..tostring(err)) end
end
last.rebirth = nowx()
end
end
print("FARM_EXIT gen stale")
end)
print("HUB v3 started gen="..GEN)