-- Auto Farm Script
-- By @mr_opensourced
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local player = Players.LocalPlayer
local playerGui = player:WaitForChild("PlayerGui")
-- State
local farmEnabled = false
local farmThread = nil
local originalCFrame = nil
-- GUI
local screenGui = Instance.new("ScreenGui")
screenGui.Name = "AutoFarmGui"
screenGui.ResetOnSpawn = false
screenGui.Parent = playerGui
local mainFrame = Instance.new("Frame")
mainFrame.Size = UDim2.new(0, 220, 0, 90)
mainFrame.Position = UDim2.new(0.5, -110, 0, 20)
mainFrame.BackgroundColor3 = Color3.fromRGB(20, 20, 20)
mainFrame.BorderSizePixel = 0
mainFrame.Active = true
mainFrame.Draggable = true
mainFrame.Parent = screenGui
Instance.new("UICorner", mainFrame).CornerRadius = UDim.new(0, 8)
local titleLabel = Instance.new("TextLabel")
titleLabel.Size = UDim2.new(1, 0, 0, 30)
titleLabel.Position = UDim2.new(0, 0, 0, 0)
titleLabel.BackgroundTransparency = 1
titleLabel.Text = "Auto Farm | @mr_opensourced"
titleLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
titleLabel.TextSize = 12
titleLabel.Font = Enum.Font.GothamBold
titleLabel.Parent = mainFrame
local statusLabel = Instance.new("TextLabel")
statusLabel.Size = UDim2.new(1, 0, 0, 20)
statusLabel.Position = UDim2.new(0, 0, 0, 28)
statusLabel.BackgroundTransparency = 1
statusLabel.Text = "Status: OFF"
statusLabel.TextColor3 = Color3.fromRGB(255, 80, 80)
statusLabel.TextSize = 12
statusLabel.Font = Enum.Font.Gotham
statusLabel.Parent = mainFrame
local toggleBtn = Instance.new("TextButton")
toggleBtn.Size = UDim2.new(0, 180, 0, 28)
toggleBtn.Position = UDim2.new(0.5, -90, 0, 54)
toggleBtn.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
toggleBtn.BorderSizePixel = 0
toggleBtn.Text = "Toggle Farm"
toggleBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
toggleBtn.TextSize = 13
toggleBtn.Font = Enum.Font.GothamBold
toggleBtn.Parent = mainFrame
Instance.new("UICorner", toggleBtn).CornerRadius = UDim.new(0, 6)
-- Safely get root part
local function getRoot()
local char = player.Character
if not char then return nil end
return char:FindFirstChild("HumanoidRootPart")
end
-- Teleport helper
local function tpTo(cf)
local root = getRoot()
if root then
root.CFrame = cf
task.wait(0.1)
end
end
-- Force fire proximity prompt bypassing range check
local function fireProximityInstant(prompt)
-- Temporarily override MaxActivationDistance
local oldDist = prompt.MaxActivationDistance
prompt.MaxActivationDistance = math.huge
task.wait(0.05)
local ok, err = pcall(function()
fireproximityprompt(prompt)
end)
if not ok then
-- fallback: use remote if fireproximityprompt unavailable
warn("fireproximityprompt failed: " .. tostring(err))
end
task.wait(0.05)
prompt.MaxActivationDistance = oldDist
end
-- Trigger all proximityprompts in an item
local function triggerProximity(item)
for _, v in ipairs(item:GetDescendants()) do
if v:IsA("ProximityPrompt") then
fireProximityInstant(v)
end
end
end
-- Get CFrame of an item
local function getItemCFrame(item)
if item:IsA("BasePart") then
return item.CFrame
end
local part = item:FindFirstChildWhichIsA("BasePart")
if part then return part.CFrame end
return nil
end
-- Return to CollectHitbox
local function returnToHitbox()
local hitbox = workspace:FindFirstChild("CollectHitbox")
if hitbox and hitbox:IsA("BasePart") then
tpTo(hitbox.CFrame + Vector3.new(0, 3, 0))
elseif originalCFrame then
tpTo(originalCFrame)
end
end
-- Main farm loop
local function farmItems()
local root = getRoot()
if not root then warn("No character found") return end
-- Save position
originalCFrame = root.CFrame
local rarityFolder = workspace:FindFirstChild("RarityParts")
if not rarityFolder then warn("RarityParts not found in workspace") return end
local children = rarityFolder:GetChildren()
local rarityPart = children[18]
if not rarityPart then warn("RarityParts[18] does not exist (only " .. #children .. " children)") return end
local itemsFolder = rarityPart:FindFirstChild("Items")
if not itemsFolder then warn("No 'Items' folder inside " .. rarityPart.Name) return end
local items = itemsFolder:GetChildren()
if #items == 0 then warn("Items folder is empty") return end
print("[AutoFarm] Found " .. #items .. " items in " .. rarityPart.Name)
for _, item in ipairs(items) do
if not farmEnabled then break end
local cf = getItemCFrame(item)
if cf then
tpTo(cf + Vector3.new(0, 3, 0))
triggerProximity(item)
task.wait(0.3)
-- Return to CollectHitbox after each item
returnToHitbox()
task.wait(0.2)
end
end
print("[AutoFarm] Cycle complete, returned to CollectHitbox")
end
-- Toggle
local function setFarm(state)
farmEnabled = state
if state then
statusLabel.Text = "Status: ON"
statusLabel.TextColor3 = Color3.fromRGB(80, 255, 120)
toggleBtn.BackgroundColor3 = Color3.fromRGB(30, 80, 30)
farmThread = task.spawn(function()
while farmEnabled do
local ok, err = pcall(farmItems)
if not ok then
warn("[AutoFarm] Error: " .. tostring(err))
end
task.wait(1)
end
end)
else
farmEnabled = false
statusLabel.Text = "Status: OFF"
statusLabel.TextColor3 = Color3.fromRGB(255, 80, 80)
toggleBtn.BackgroundColor3 = Color3.fromRGB(40, 40, 40)
if farmThread then
task.cancel(farmThread)
farmThread = nil
end
end
end
toggleBtn.MouseButton1Click:Connect(function()
setFarm(not farmEnabled)
end)
print("[AutoFarm] Loaded | @mr_opensourced")
Comments
No comments yet
Be the first to share your thoughts!