local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local UserInputService = game:GetService("UserInputService") local RunService = game:GetService("RunService") local StarterGui = game:GetService("StarterGui") local USE_TELEPORT = true local TOGGLE_KEY = Enum.KeyCode.F local LocalPlayer = Players.LocalPlayer local enabled = false local collecting = false local connections = {} local candyData = {} local toggleButton = nil local function Cleanup() enabled = false if toggleButton and toggleButton.Parent then toggleButton:Destroy() end for _, conn in ipairs(connections) do if conn and conn.Connected then conn:Disconnect() end end table.clear(connections) table.clear(candyData) _G.CandyAutoCleanup = nil print("[CandyAuto] Cleanup completed") end _G.CandyAutoCleanup = Cleanup print("[CandyAuto] Initializing...") if not LocalPlayer then warn("[CandyAuto] LocalPlayer not found!") return end local CandyFolder = ReplicatedStorage:WaitForChild("Candy2026") if not CandyFolder then warn("[CandyAuto] Candy2026 folder not found!") return end local Remote = CandyFolder:WaitForChild("Remote") if not Remote then warn("[CandyAuto] Remote not found!") return end print("[CandyAuto] LocalPlayer:", LocalPlayer.Name) print("[CandyAuto] RemoteEvent ready") local function CreateToggleUI() local screenGui = Instance.new("ScreenGui") screenGui.Name = "CandyAutoToggleGui" screenGui.ResetOnSpawn = false screenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling screenGui.Parent = game:GetService("CoreGui") local button = Instance.new("TextButton") button.Name = "ToggleButton" button.Size = UDim2.new(0, 150, 0, 40) button.Position = UDim2.new(0, 10, 0, 10) -- Top-left button.BackgroundColor3 = Color3.fromRGB(0, 120, 215) button.TextColor3 = Color3.new(1, 1, 1) button.Font = Enum.Font.SourceSansBold button.TextSize = 18 button.Text = "Farm: OFF" button.Parent = screenGui local corner = Instance.new("UICorner") corner.CornerRadius = UDim.new(0, 6) corner.Parent = button return button end toggleButton = CreateToggleUI() print("[CandyAuto] Toggle UI created") table.insert(connections, Remote.OnClientEvent:Connect(function(event, data) if event == "Snapshot" then if typeof(data) == "table" then table.clear(candyData) for _, candy in ipairs(data) do if candy and candy.id then candyData[candy.id] = candy end end end elseif event == "Add" then if typeof(data) == "table" then for _, candy in ipairs(data) do if candy and candy.id then candyData[candy.id] = candy end end end elseif (event == "Collected" or event == "Remove") and data and data.id then candyData[data.id] = nil end end)) table.insert(connections, toggleButton.MouseButton1Click:Connect(function() enabled = not enabled toggleButton.Text = "Farm: " .. (enabled and "ON" or "OFF") toggleButton.BackgroundColor3 = enabled and Color3.fromRGB(0, 180, 0) or Color3.fromRGB(0, 120, 215) print("[CandyAuto] Toggled", enabled and "ON" or "OFF") end)) table.insert(connections, UserInputService.InputBegan:Connect(function(input, gameProcessed) if gameProcessed then return end if input.KeyCode == TOGGLE_KEY then enabled = not enabled toggleButton.Text = "Farm: " .. (enabled and "ON" or "OFF") toggleButton.BackgroundColor3 = enabled and Color3.fromRGB(0, 180, 0) or Color3.fromRGB(0, 120, 215) print("[CandyAuto] Toggled via keybind:", enabled and "ON" or "OFF") end end)) local function GetCharacterParts() local character = LocalPlayer.Character if not character then return nil, nil end return character:FindFirstChildOfClass("Humanoid"), character:FindFirstChild("HumanoidRootPart") end local function TeleportTo(position) local _, hrp = GetCharacterParts() if not hrp then return false end hrp.CFrame = CFrame.new(position) wait(0.1) return true end local function CollectAll() if collecting then return end collecting = true local list = {} for _, candy in pairs(candyData) do table.insert(list, candy) end if #list == 0 then collecting = false return end local _, hrp = GetCharacterParts() if not hrp then collecting = false return end table.sort(list, function(a, b) return (hrp.Position - a.position).Magnitude < (hrp.Position - b.position).Magnitude end) for _, candy in ipairs(list) do if not enabled then break end if not TeleportTo(candy.position) then end wait(0.2) end collecting = false end print("[CandyAuto] Starting main loop...") spawn(function() while true do wait(1.5) if not LocalPlayer.Parent then print("[CandyAuto] LocalPlayer removed, exiting") break end pcall(function() Remote:FireServer("Sync") end) if enabled and not collecting then wait(0.5) pcall(CollectAll) end end print("[CandyAuto] Main loop ended") Cleanup() end) print("[CandyAuto] Lets larp one last time") print("[CandyAuto] Current state: Farm: OFF (tap button to turn ON)")