Created
July 24, 2026 14:51
-
-
Save DuyNgao2306/43b4a2a439884ff18c65be67fa9c770d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- [[ SMART MACRO - OPTIMIZED VERSION ]] -- | |
| local Players = game:GetService("Players") | |
| local UserInputService = game:GetService("UserInputService") | |
| local VirtualUser = game:GetService("VirtualUser") | |
| local LocalPlayer = Players.LocalPlayer | |
| local PlayerGui = LocalPlayer:WaitForChild("PlayerGui") | |
| -- Xóa GUI cũ nếu tồn tại trong PlayerGui | |
| if PlayerGui:FindFirstChild("MacroSystemGui") then | |
| PlayerGui.MacroSystemGui:Destroy() | |
| end | |
| -- Biến cục bộ quản lý trạng thái | |
| local recordedClicks = {} | |
| local MAX_CLICKS = 200 -- Giới hạn an toàn, tránh phình to bộ nhớ | |
| local isSelecting = false | |
| local isRunning = false | |
| local lastClickTime = 0 | |
| local connections = {} -- Bảng chứa toàn bộ event để Disconnect sau này | |
| -- 1. TẠO GIAO DIỆN (UI) | |
| local ScreenGui = Instance.new("ScreenGui") | |
| ScreenGui.Name = "MacroSystemGui" | |
| ScreenGui.ResetOnSpawn = false | |
| ScreenGui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling | |
| ScreenGui.DisplayOrder = 999 | |
| ScreenGui.Parent = PlayerGui | |
| local MainFrame = Instance.new("Frame") | |
| MainFrame.Name = "MainFrame" | |
| MainFrame.Size = UDim2.new(0, 300, 0, 220) | |
| MainFrame.Position = UDim2.new(0.5, -150, 0.3, 0) | |
| MainFrame.BackgroundColor3 = Color3.fromRGB(25, 27, 38) | |
| MainFrame.BorderSizePixel = 0 | |
| MainFrame.Active = true -- RẤT QUAN TRỌNG: Giúp gameProcessed nhận diện khi click vào UI | |
| MainFrame.ZIndex = 1 | |
| MainFrame.Parent = ScreenGui | |
| local UICorner = Instance.new("UICorner") | |
| UICorner.CornerRadius = UDim.new(0, 10) | |
| UICorner.Parent = MainFrame | |
| local UIStroke = Instance.new("UIStroke") | |
| UIStroke.Color = Color3.fromRGB(60, 65, 85) | |
| UIStroke.Thickness = 1.5 | |
| UIStroke.Parent = MainFrame | |
| -- Header | |
| local Header = Instance.new("Frame") | |
| Header.Size = UDim2.new(1, 0, 0, 38) | |
| Header.BackgroundColor3 = Color3.fromRGB(35, 38, 52) | |
| Header.BorderSizePixel = 0 | |
| Header.ZIndex = 2 | |
| Header.Parent = MainFrame | |
| local HeaderCorner = Instance.new("UICorner") | |
| HeaderCorner.CornerRadius = UDim.new(0, 10) | |
| HeaderCorner.Parent = Header | |
| local Title = Instance.new("TextLabel") | |
| Title.Size = UDim2.new(1, -50, 1, 0) | |
| Title.Position = UDim2.new(0, 12, 0, 0) | |
| Title.BackgroundTransparency = 1 | |
| Title.Text = "⚡ SMART MACRO" | |
| Title.TextColor3 = Color3.fromRGB(255, 255, 255) | |
| Title.TextSize = 14 | |
| Title.Font = Enum.Font.GothamBold | |
| Title.TextXAlignment = Enum.TextXAlignment.Left | |
| Title.Active = false | |
| Title.ZIndex = 3 | |
| Title.Parent = Header | |
| -- Nút Xóa UI (Nút X) | |
| local CloseBtn = Instance.new("TextButton") | |
| CloseBtn.Size = UDim2.new(0, 30, 0, 30) | |
| CloseBtn.Position = UDim2.new(1, -5, 0.5, 0) | |
| CloseBtn.AnchorPoint = Vector2.new(1, 0.5) | |
| CloseBtn.BackgroundTransparency = 1 | |
| CloseBtn.Text = "✕" | |
| CloseBtn.TextColor3 = Color3.fromRGB(255, 71, 87) | |
| CloseBtn.TextSize = 18 | |
| CloseBtn.Font = Enum.Font.GothamBold | |
| CloseBtn.ZIndex = 10 | |
| CloseBtn.Parent = Header | |
| -- Labels | |
| local StatusLabel = Instance.new("TextLabel") | |
| StatusLabel.Size = UDim2.new(1, -24, 0, 20) | |
| StatusLabel.Position = UDim2.new(0, 12, 0, 48) | |
| StatusLabel.BackgroundTransparency = 1 | |
| StatusLabel.Text = "Trạng thái: Đang nghỉ" | |
| StatusLabel.TextColor3 = Color3.fromRGB(180, 185, 200) | |
| StatusLabel.TextSize = 12 | |
| StatusLabel.Font = Enum.Font.GothamMedium | |
| StatusLabel.TextXAlignment = Enum.TextXAlignment.Left | |
| StatusLabel.Active = false | |
| StatusLabel.Parent = MainFrame | |
| local CountLabel = Instance.new("TextLabel") | |
| CountLabel.Size = UDim2.new(1, -24, 0, 20) | |
| CountLabel.Position = UDim2.new(0, 12, 0, 68) | |
| CountLabel.BackgroundTransparency = 1 | |
| CountLabel.Text = "Đã lưu: 0 / " .. MAX_CLICKS | |
| CountLabel.TextColor3 = Color3.fromRGB(130, 135, 150) | |
| CountLabel.TextSize = 11 | |
| CountLabel.Font = Enum.Font.Gotham | |
| CountLabel.TextXAlignment = Enum.TextXAlignment.Left | |
| CountLabel.Active = false | |
| CountLabel.Parent = MainFrame | |
| -- Hàm tạo Nút bấm chuẩn | |
| local function createButton(name, text, pos, size, color) | |
| local btn = Instance.new("TextButton") | |
| btn.Name = name | |
| btn.Size = size | |
| btn.Position = pos | |
| 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.Active = true | |
| btn.ZIndex = 10 | |
| 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, 12, 0, 98), UDim2.new(1, -24, 0, 34), Color3.fromRGB(108, 92, 231)) | |
| local StartBtn = createButton("StartBtn", "Starts", UDim2.new(0, 12, 0, 140), UDim2.new(0, 175, 0, 34), Color3.fromRGB(0, 184, 148)) | |
| local ClearBtn = createButton("ClearBtn", "Xóa", UDim2.new(0, 195, 0, 140), UDim2.new(0, 93, 0, 34), Color3.fromRGB(225, 112, 85)) | |
| -- Hàm gắn sự kiện UI tiêu chuẩn (Sử dụng Activated) | |
| local function bindClick(button, callback) | |
| table.insert(connections, button.Activated:Connect(callback)) | |
| end | |
| -- 2. TÍNH NĂNG CHỐNG AFK | |
| table.insert(connections, LocalPlayer.Idled:Connect(function() | |
| VirtualUser:CaptureController() | |
| VirtualUser:ClickButton2(Vector2.zero) | |
| end)) | |
| -- 3. KÉO THẢ UI (DRAGGABLE) | |
| local dragging, dragStart, startPos | |
| table.insert(connections, 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 | |
| end | |
| end)) | |
| table.insert(connections, UserInputService.InputChanged:Connect(function(input) | |
| if dragging and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) 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)) | |
| table.insert(connections, UserInputService.InputEnded:Connect(function(input) | |
| if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then | |
| dragging = false | |
| end | |
| end)) | |
| -- 4. 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" | |
| 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: Hoàn tất chọn" | |
| StatusLabel.TextColor3 = Color3.fromRGB(180, 185, 200) | |
| end | |
| -- Thu thập điểm click bằng input.Position | |
| table.insert(connections, UserInputService.InputBegan:Connect(function(input, gameProcessed) | |
| if not isSelecting then return end | |
| -- Tính năng an toàn: Bỏ qua click nếu đang bấm vào UI (Vì UI đã gán Active = true) | |
| if gameProcessed then return end | |
| if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then | |
| -- Giới hạn số lượng điểm click | |
| if #recordedClicks >= MAX_CLICKS then | |
| StatusLabel.Text = "Lỗi: Đã đạt mốc tối đa " .. MAX_CLICKS .. " điểm!" | |
| StatusLabel.TextColor3 = Color3.fromRGB(255, 118, 117) | |
| return | |
| end | |
| local now = os.clock() | |
| local delayTime = (#recordedClicks > 0) and math.max(now - lastClickTime, 0.05) or 0.1 | |
| lastClickTime = now | |
| table.insert(recordedClicks, { | |
| x = input.Position.X, -- Sử dụng Input Position thay cho Mouse | |
| y = input.Position.Y, | |
| delay = delayTime | |
| }) | |
| CountLabel.Text = "Đã lưu: " .. #recordedClicks .. " / " .. MAX_CLICKS | |
| StatusLabel.Text = "Trạng thái: +1 điểm click mới!" | |
| StatusLabel.TextColor3 = Color3.fromRGB(253, 203, 110) | |
| end | |
| end)) | |
| -- Gán sự kiện bằng chuẩn Activated | |
| bindClick(SelectBtn, 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: Hãy click vào màn hình..." | |
| StatusLabel.TextColor3 = Color3.fromRGB(253, 203, 110) | |
| lastClickTime = os.clock() | |
| else | |
| stopSelecting() | |
| end | |
| end) | |
| bindClick(StartBtn, function() | |
| if isSelecting then stopSelecting() end | |
| if isRunning then | |
| stopRunning() | |
| return | |
| end | |
| if #recordedClicks == 0 then | |
| StatusLabel.Text = "Lỗi: Chưa lưu điểm 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) | |
| task.spawn(function() | |
| while isRunning do | |
| for _, data in ipairs(recordedClicks) do | |
| if not isRunning then break end | |
| task.wait(data.delay) | |
| if not isRunning then break end | |
| -- Gửi sự kiện Click vào hệ thống giả lập | |
| VirtualUser:Button1Down(Vector2.new(data.x, data.y)) | |
| task.wait(0.02) | |
| VirtualUser:Button1Up(Vector2.new(data.x, data.y)) | |
| end | |
| task.wait(0.05) | |
| end | |
| end) | |
| end) | |
| bindClick(ClearBtn, function() | |
| if isRunning then stopRunning() end | |
| if isSelecting then stopSelecting() end | |
| table.clear(recordedClicks) | |
| CountLabel.Text = "Đã lưu: 0 / " .. MAX_CLICKS | |
| StatusLabel.Text = "Trạng thái: Đã xóa toàn bộ bộ nhớ" | |
| StatusLabel.TextColor3 = Color3.fromRGB(180, 185, 200) | |
| end) | |
| -- Nút Tắt & Dọn Rác (Garbage Collection) | |
| bindClick(CloseBtn, function() | |
| isRunning = false | |
| isSelecting = false | |
| -- Dọn dẹp ngắt toàn bộ Event Listener tránh Memory Leak | |
| for _, conn in ipairs(connections) do | |
| if conn.Connected then | |
| conn:Disconnect() | |
| end | |
| end | |
| table.clear(connections) | |
| ScreenGui:Destroy() | |
| end) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment