AutoBuy
Key Required

AutoBuy

[⚡EVENT] Idle DefenseMediorceExploiterMediorceExploiter 3.4K views 46 executesUpdated Dec 7, 2025
Unrated
00
Lua Script•102 lines (2019 chars)
--// BuyUnit Auto Caller
--// Toggle: K
--// Unload: M

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local UserInputService = game:GetService("UserInputService")

--====================
-- CONFIG
--====================
local TOGGLE_KEY = Enum.KeyCode.K
local UNLOAD_KEY = Enum.KeyCode.M
local FIRE_DELAY = 0.05 -- adjust if needed

local remote = ReplicatedStorage:WaitForChild("BuyUnit")
--Shop Names
--AdvancedUnitShop
--MainUnitShop
local ARGS = {
	"AdvancedUnitShop",
	50,
	{	--Unit Rarity that will be auto-sold on purchase.
		Legendary = true,
		Common = true,
		Epic = true,
		Mythic = true,
		Rare = true,
	}
}

--====================
-- Singleton
--====================
local SINGLETON_KEY = "_AUTO_BUY_LUNAR_V1"
local env = (getgenv and getgenv()) or _G

if env[SINGLETON_KEY] then
	pcall(env[SINGLETON_KEY])
end

local enabled = false
local loopToken = 0
local connections = {}

local function cleanup()
	enabled = false
	loopToken += 1
	for _, c in ipairs(connections) do
		pcall(function() c:Disconnect() end)
	end
	connections = {}
	env[SINGLETON_KEY] = nil
	print("[AutoBuy] Unloaded.")
end

env[SINGLETON_KEY] = cleanup

local function connect(sig, fn)
	local c = sig:Connect(fn)
	table.insert(connections, c)
	return c
end

--====================
-- Loop
--====================
local function startLoop()
	loopToken += 1
	local myToken = loopToken

	task.spawn(function()
		print("[AutoBuy] Started.")
		while enabled and loopToken == myToken do
			pcall(function()
				remote:InvokeServer(table.unpack(ARGS))
			end)
			task.wait(FIRE_DELAY)
		end
		print("[AutoBuy] Stopped.")
	end)
end

--====================
-- Controls
--====================
connect(UserInputService.InputBegan, function(input, gp)
	if gp then return end

	if input.KeyCode == TOGGLE_KEY then
		enabled = not enabled
		if enabled then
			startLoop()
		else
			print("[AutoBuy] Toggled OFF.")
		end

	elseif input.KeyCode == UNLOAD_KEY then
		cleanup()
	end
end)

print("[AutoBuy] Ready | Toggle: K | Unload: M")

Features & Information

Just Press K, EASY MONEY, Shops I know AdvancedUnitShop MainUnitShop Buy Settings 1, 10, 25, 50 The true & false settings are for auto-sell.
#autobuy#idle defense

Community Comments (6)

NatoPayoNatoPayoDec 15, 2025

Im not the smartest cookie but like what does this do? I hear a noise sometimes but thats it

Replying to @NatoPayo
MediorceExploiterMediorceExploiterDec 20, 2025

@NatoPayo open unit shop, and you'll see the change

MediorceExploiterMediorceExploiterDec 20, 2025

OMG, I UPLOADED THE WRONG SCRIPT 😭😭😭😭

MediorceExploiterMediorceExploiterApr 14, 2026

Guys, ts is lowk ahh, I'm updating it 🥳

nothingmreasynothingmreasyMay 1, 2026

Where's the replaced script code

Replying to @nothingmreasy

@nothingmreasy old or new?

More Scripts for [⚡EVENT] Idle Defense