Skip to content
RoRoScripts
AutoFarm Open Source preview
Unknown

AutoFarm Open Source

Script
Views
303
Likes
1
Dislikes
0
Added
Script
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local nativePrint = print

local player = Players.LocalPlayer
local events = ReplicatedStorage:WaitForChild("Events")
local configs = ReplicatedStorage:WaitForChild("Configs")
local weightsConfig = require(configs:WaitForChild("WeightsConfig"))
local dnkConfig = require(configs:WaitForChild("DnkConfig"))
local stagesConfig = require(configs:WaitForChild("StagesConfig"))
local dataClient = require(ReplicatedStorage:WaitForChild("Data")).client

local gameEnvironment = getfenv(getmetatable(dataClient).__index)
hookfunction(gameEnvironment.print, function() end)
hookfunction(gameEnvironment.warn, function() end)

local function log(message)
	nativePrint("[LiftFarm] " .. tostring(message))
end

local sellMuscleRemote = events:WaitForChild("SellMuscle")
local buyWeightRemote = events:WaitForChild("BuyWeight")
local buyDnkRemote = events:WaitForChild("BuyDnk")
local buyStageRemote = events:WaitForChild("BuyStage")
local equipRemote = events:WaitForChild("Equip")

local LIFT_INTERVAL = 1 / 30
local SELL_PERCENT = 0.98
local SELL_INTERVAL = 2
local EQUIP_WAIT = 0.3
local RETRY_WAIT = 1
local GAIN_TICK = 60
local CAPACITY_MARGIN = 2
local MAX_UPGRADES = 40

local function getCharacter()
	local character = player.Character
	if character and character:FindFirstChildOfClass("Humanoid") then
		return character
	end
	return player.CharacterAdded:Wait()
end

local function findWeightTool(character)
	for _, item in ipairs(character:GetChildren()) do
		if item:IsA("Tool") and item:GetAttribute("IsWeight") then
			return item
		end
	end
	local backpack = player:FindFirstChild("Backpack")
	if backpack then
		for _, item in ipairs(backpack:GetChildren()) do
			if item:IsA("Tool") and item:GetAttribute("IsWeight") then
				return item
			end
		end
	end
	return nil
end

local function equipWeight(character, tool)
	local humanoid = character:FindFirstChildOfClass("Humanoid")
	if not humanoid then
		return false
	end
	pcall(function()
		humanoid:EquipTool(tool)
	end)
	task.wait(EQUIP_WAIT)
	return tool.Parent == character
end

local function requestWeightGrant()
	pcall(function()
		equipRemote:InvokeServer(dataClient.CurrentWeight(), "Weights")
	end)
end

local function musclePerSecond()
	local weightEntry = weightsConfig[dataClient.CurrentWeight()]
	if not weightEntry then
		return 0
	end
	return weightEntry.MuscleGain * dataClient.StrengthBoost() * GAIN_TICK
end

local function buyWeights()
	local bought = 0
	local index = dataClient.MaxUnlockedWeight()
	local coins = dataClient.Coins()
	while bought < MAX_UPGRADES do
		local entry = weightsConfig[index]
		if not entry or entry.donate or entry.Price > coins then
			break
		end
		local success, result = pcall(function()
			return buyWeightRemote:InvokeServer(index, weightsConfig, "Weights")
		end)
		if not success or not result then
			break
		end
		coins -= entry.Price
		bought += 1
		index += 1
		task.wait()
	end
	return bought
end

local function buyDnks()
	local bought = 0
	local index = dataClient.CurrentDnk() + 1
	local coins = dataClient.Coins()
	while bought < MAX_UPGRADES and dataClient.Dnk_capacity() < musclePerSecond() * CAPACITY_MARGIN do
		local entry = dnkConfig[index]
		if not entry or entry.donate or entry.Price > coins then
			break
		end
		local success, result = pcall(function()
			return buyDnkRemote:InvokeServer(index)
		end)
		if not success or not result then
			break
		end
		coins -= entry.Price
		bought += 1
		index += 1
		task.wait()
	end
	return bought
end

local function buyStages()
	local bought = 0
	local index = dataClient.BestStage() + 1
	local coins = dataClient.Coins()
	while bought < MAX_UPGRADES do
		local entry = stagesConfig[index]
		if not entry or entry.Price > coins then
			break
		end
		local success, result = pcall(function()
			return buyStageRemote:InvokeServer(index)
		end)
		if not success or not result then
			break
		end
		coins -= entry.Price
		bought += 1
		index += 1
		task.wait()
	end
	return bought
end

local function upgrade()
	local weightCount = buyWeights()
	local dnkCount = buyDnks()
	local stageCount = buyStages()
	if weightCount + dnkCount + stageCount > 0 then
		log(string.format("upgrade | weight +%d | dnk +%d | stage +%d", weightCount, dnkCount, stageCount))
	end
end

local function liftWeight(character, tool)
	local threshold = dataClient.Dnk_capacity() * SELL_PERCENT
	local deadline = os.clock() + SELL_INTERVAL
	while dataClient.Muscle() < threshold and os.clock() < deadline do
		if tool.Parent ~= character then
			return false
		end
		tool:Activate()
		task.wait(LIFT_INTERVAL)
	end
	return true
end

local function sellMuscle()
	local success, gained = pcall(function()
		return sellMuscleRemote:InvokeServer()
	end)
	if success and gained and gained > 0 then
		log(string.format("sold %s | coins %s", tostring(gained), tostring(dataClient.Coins())))
	end
end

log(string.format("started | weight %d | stage %d | dnk %d | capacity %s", dataClient.CurrentWeight(), dataClient.Stage(), dataClient.CurrentDnk(), tostring(dataClient.Dnk_capacity())))

while true do
	upgrade()
	local character = getCharacter()
	local tool = findWeightTool(character)
	if tool then
		if tool.Parent ~= character and not equipWeight(character, tool) then
			task.wait(RETRY_WAIT)
			continue
		end
		if liftWeight(character, tool) then
			sellMuscle()
		end
	else
		requestWeightGrant()
		task.wait(RETRY_WAIT)
	end
end

Features

  • i got you