Skip to content

Instantly share code, notes, and snippets.

@DuyNgao2306
Created July 24, 2026 14:40
Show Gist options
  • Select an option

  • Save DuyNgao2306/9917cd003fb8ff1699f3559c7ab8ed34 to your computer and use it in GitHub Desktop.

Select an option

Save DuyNgao2306/9917cd003fb8ff1699f3559c7ab8ed34 to your computer and use it in GitHub Desktop.
-- [[ SMART MACRO SYSTEM - ROBLOX STUDIO ]] --
-- Vị trí khuyến nghị: StarterPlayerScripts hoặc StarterGui
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local VirtualInputManager = game:GetService("VirtualInputManager")
local VirtualUser = game:GetService("VirtualUser")
local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")
-- 1. CHỐNG OUT SERVER (ANTI-AFK AUTOMATIC)
LocalPlayer.Idled:Connect(function()
VirtualUser:CaptureController()
VirtualUser:ClickButton2(Vector2.zero)
end)
-- Biến quản lý trạng thái
local isSelecting = false
local isRunning = false
local recordedClicks = {}
local lastClickTime = 0
-- 2. TẠO GIAO DIỆN BEAUTIFUL UI (MODERN DARK THEME)
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "SmartMacroUI"
ScreenGui.ResetOnSpawn = false
ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
ScreenGui.Parent = PlayerGui
local MainFrame = Instance.new("Frame")
MainFrame.Name = "MainFrame"
MainFrame.Size = UDim2.new(0, 320, 0, 230)
MainFrame.Position = UDim2.new(0.5, -160, 0.35, -115)
MainFrame.BackgroundColor3 = Color3.fromRGB(24, 26, 36)
MainFrame.BorderSizePixel = 0
MainFrame.ClipsDescendants = true
MainFrame.Parent = ScreenGui
local UICorner = Instance.new("UICorner")
UICorner.CornerRadius = UDim.new(0, 12)
UICorner.Parent = MainFrame
local UIStroke = Instance.new("UIStroke")
UIStroke.Color = Color3.fromRGB(55, 60, 80)
UIStroke.Thickness = 1.5
UIStroke.Parent = MainFrame
-- Header Bar (Thanh tiêu đề)
local Header = Instance.new("Frame")
Header.Name = "Header"
Header.Size = UDim2.new(1, 0, 0, 40)
Header.BackgroundColor3 = Color3.fromRGB(32, 35, 48)
Header.BorderSizePixel = 0
Header.Parent = MainFrame
local HeaderCorner = Instance.new("UICorner")
HeaderCorner.CornerRadius = UDim.new(0, 12)
HeaderCorner.Parent = Header
local Title = Instance.new("TextLabel")
Title.Size = UDim2.new(1, -20, 1, 0)
Title.Position = UDim2.new(0, 15, 0, 0)
Title.BackgroundTransparency = 1
Title.Text = "⚡ SMART MACRO"
Title.TextColor3 = Color3.fromRGB(255, 255, 255)
Title.TextSize = 15
Title.Font = Enum.Font.GothamBold
Title.TextXAlignment = Enum.TextXAlignment.Left
Title.Parent = Header
-- Thông tin trạng thái
local StatusLabel = Instance.new("TextLabel")
StatusLabel.Size = UDim2.new(1, -30, 0, 20)
StatusLabel.Position = UDim2.new(0, 15, 0, 50)
StatusLabel.BackgroundTransparency = 1
StatusLabel.Text = "Trạng thái: Đang nghỉ"
StatusLabel.TextColor3 = Color3.fromRGB(180, 185, 200)
StatusLabel.TextSize = 13
StatusLabel.Font = Enum.Font.GothamMedium
StatusLabel.TextXAlignment = Enum.TextXAlignment.Left
StatusLabel.Parent = MainFrame
local CountLabel = Instance.new("TextLabel")
CountLabel.Size = UDim2.new(1, -30, 0, 20)
CountLabel.Position = UDim2.new(0, 15, 0, 72)
CountLabel.BackgroundTransparency = 1
CountLabel.Text = "Đã ghi nhận: 0 điểm click"
CountLabel.TextColor3 = Color3.fromRGB(130, 135, 150)
CountLabel.TextSize = 12
CountLabel.Font = Enum.Font.Gotham
CountLabel.TextXAlignment = Enum.TextXAlignment.Left
CountLabel.Parent = MainFrame
-- Hàm tạo Nút bấm đẹp
local function createButton(name, text, position, size, color)
local btn = Instance.new("TextButton")
btn.Name = name
btn.Size = size
btn.Position = position
btn.BackgroundColor3 = color
btn.Text = text
btn.TextColor3 = Color3.fromRGB(255, 255, 255)
btn.Font = Enum.Font.GothamBold
btn.TextSize = 13
btn.AutoButtonColor = true
btn.Parent = MainFrame
local corner = Instance.new("UICorner")
corner.CornerRadius = UDim.new(0, 8)
corner.Parent = btn
return btn
end
local SelectBtn = createButton("SelectBtn", "Start selecting", UDim2.new(0, 15, 0, 102), UDim2.new(1, -30, 0, 36), Color3.fromRGB(108, 92, 231))
local StartBtn = createButton("StartBtn", "Starts", UDim2.new(0, 15, 0, 146), UDim2.new(0, 185, 0, 36), Color3.fromRGB(0, 184, 148))
local ClearBtn = createButton("ClearBtn", "Xóa", UDim2.new(0, 208, 0, 146), UDim2.new(0, 97, 0, 36), Color3.fromRGB(225, 112, 85))
local FooterLabel = Instance.new("TextLabel")
FooterLabel.Size = UDim2.new(1, -30, 0, 15)
FooterLabel.Position = UDim2.new(0, 15, 0, 195)
FooterLabel.BackgroundTransparency = 1
FooterLabel.Text = "🛡️ Tự động bật Anti-AFK Kick"
FooterLabel.TextColor3 = Color3.fromRGB(0, 206, 201)
FooterLabel.TextSize = 11
FooterLabel.Font = Enum.Font.Gotham
FooterLabel.TextXAlignment = Enum.TextXAlignment.Center
FooterLabel.Parent = MainFrame
-- Kéo thả UI (Draggable support PC & Mobile)
local dragging, dragInput, dragStart, startPos
Header.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
dragging = true
dragStart = input.Position
startPos = MainFrame.Position
input.Changed:Connect(function()
if input.UserInputState == Enum.UserInputState.End then
dragging = false
end
end)
end
end)
Header.InputChanged:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch then
dragInput = input
end
end)
UserInputService.InputChanged:Connect(function(input)
if input == dragInput and dragging then
local delta = input.Position - dragStart
MainFrame.Position = UDim2.new(startPos.X.Scale, startPos.X.Offset + delta.X, startPos.Y.Scale, startPos.Y.Offset + delta.Y)
end
end)
-- 3. LOGIC XỬ LÝ MACRO
local function stopRunning()
isRunning = false
StartBtn.Text = "Starts"
StartBtn.BackgroundColor3 = Color3.fromRGB(0, 184, 148)
StatusLabel.Text = "Trạng thái: Đã dừng Macro"
StatusLabel.TextColor3 = Color3.fromRGB(180, 185, 200)
end
local function stopSelecting()
isSelecting = false
SelectBtn.Text = "Start selecting"
SelectBtn.BackgroundColor3 = Color3.fromRGB(108, 92, 231)
StatusLabel.Text = "Trạng thái: Đã dừng chọn"
StatusLabel.TextColor3 = Color3.fromRGB(180, 185, 200)
end
-- Ghi nhận vị trí Click
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if not isSelecting then return end
if gameProcessed then return end -- Tránh nhận diện khi bấm trúng UI
if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
local mousePos = UserInputService:GetMouseLocation()
local now = os.clock()
local delayTime = 0.1
if #recordedClicks > 0 then
delayTime = math.max(now - lastClickTime, 0.05)
end
lastClickTime = now
table.insert(recordedClicks, {
pos = mousePos,
delay = delayTime
})
CountLabel.Text = "Đã ghi nhận: " .. #recordedClicks .. " điểm click"
StatusLabel.Text = "Trạng thái: Đã lưu vị trí click mới!"
StatusLabel.TextColor3 = Color3.fromRGB(253, 203, 110)
end
end)
-- Sự kiện bấm nút Select
SelectBtn.MouseButton1Click:Connect(function()
if isRunning then stopRunning() end
isSelecting = not isSelecting
if isSelecting then
SelectBtn.Text = "Stop selecting"
SelectBtn.BackgroundColor3 = Color3.fromRGB(225, 112, 85)
StatusLabel.Text = "Trạng thái: Đang ghi nhận click..."
StatusLabel.TextColor3 = Color3.fromRGB(253, 203, 110)
lastClickTime = os.clock()
else
stopSelecting()
end
end)
-- Sự kiện bấm nút Starts (Chạy Macro)
StartBtn.MouseButton1Click:Connect(function()
if isSelecting then stopSelecting() end
if isRunning then
stopRunning()
return
end
if #recordedClicks == 0 then
StatusLabel.Text = "Lỗi: Chưa chọn vị trí click nào!"
StatusLabel.TextColor3 = Color3.fromRGB(255, 118, 117)
return
end
isRunning = true
StartBtn.Text = "Stop Macro"
StartBtn.BackgroundColor3 = Color3.fromRGB(214, 48, 49)
StatusLabel.Text = "Trạng thái: Đang lặp lại Click..."
StatusLabel.TextColor3 = Color3.fromRGB(85, 239, 196)
-- Luồng chạy vòng lặp lặp lại hành động
task.spawn(function()
while isRunning do
for _, actionData in ipairs(recordedClicks) do
if not isRunning then break end
task.wait(actionData.delay)
if not isRunning then break end
-- Giả lập hành động click chính xác vị trí
pcall(function()
VirtualInputManager:SendMouseButtonEvent(actionData.pos.X, actionData.pos.Y, 0, true, game, 0)
task.wait(0.02)
VirtualInputManager:SendMouseButtonEvent(actionData.pos.X, actionData.pos.Y, 0, false, game, 0)
end)
end
task.wait(0.05) -- Giới hạn nhịp tránh đơ lag/văng server
end
end)
end)
-- Nút Xóa dữ liệu cũ
ClearBtn.MouseButton1Click:Connect(function()
if isRunning then stopRunning() end
if isSelecting then stopSelecting() end
recordedClicks = {}
CountLabel.Text = "Đã ghi nhận: 0 điểm click"
StatusLabel.Text = "Trạng thái: Đã xóa dữ liệu"
StatusLabel.TextColor3 = Color3.fromRGB(180, 185, 200)
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment