local ok, err = xpcall(function()
    local CoreGui = game:GetService("CoreGui")
    local parentGui = (typeof(gethui) == "function" and gethui()) or CoreGui

    local existing = parentGui:FindFirstChild("EmoteHub")
    if existing then existing:Destroy() end
    if CoreGui:FindFirstChild("EmoteHub") then CoreGui:FindFirstChild("EmoteHub"):Destroy() end

    local Players = game:GetService("Players")
    local UserInputService = game:GetService("UserInputService")
    local TweenService = game:GetService("TweenService")
    local RunService = game:GetService("RunService")
    local AvatarEditorService = game:GetService("AvatarEditorService")
    local player = Players.LocalPlayer

    local FONT_BOLD    = Enum.Font.BuilderSansBold
    local FONT_MEDIUM  = Enum.Font.BuilderSansMedium
    local FONT_REGULAR = Enum.Font.BuilderSans
    local FONT_MONO    = Enum.Font.Code

    local COLORS = {
        bg          = Color3.fromRGB(6, 7, 10),
        surface     = Color3.fromRGB(15, 17, 22),
        card        = Color3.fromRGB(13, 15, 20),
        border      = Color3.fromRGB(34, 38, 48),
        borderHover = Color3.fromRGB(70, 130, 235),
        whitePill   = Color3.fromRGB(242, 245, 250),
        darkText    = Color3.fromRGB(10, 12, 16),
        text        = Color3.fromRGB(238, 242, 248),
        subtext     = Color3.fromRGB(130, 138, 154),
        blueAccent  = Color3.fromRGB(56, 132, 245),
        blueGlow    = Color3.fromRGB(36, 98, 210),
        hexDim      = Color3.fromRGB(20, 23, 30),
        hexWhite    = Color3.fromRGB(215, 228, 248),
        scrollbar   = Color3.fromRGB(50, 58, 74),
    }

    local SORTS = {
        { label = "Popular",     sort = Enum.CatalogSortType.MostFavorited },
        { label = "Bestselling", sort = Enum.CatalogSortType.Bestselling },
        { label = "Relevance",   sort = Enum.CatalogSortType.Relevance },
        { label = "Newest",      sort = Enum.CatalogSortType.RecentlyCreated },
        { label = "Low Price",   sort = Enum.CatalogSortType.PriceLowToHigh },
        { label = "High Price",  sort = Enum.CatalogSortType.PriceHighToLow },
    }

    local gui = Instance.new("ScreenGui")
    gui.Name = "EmoteHub"
    gui.ResetOnSpawn = false
    gui.ZIndexBehavior = Enum.ZIndexBehavior.Sibling
    gui.DisplayOrder = 999
    gui.Parent = parentGui

    local main = Instance.new("Frame")
    main.Name = "Main"
    main.Size = UDim2.new(0, 368, 0, 530)
    main.Position = UDim2.new(1, -383, 0, 15)
    main.BackgroundColor3 = COLORS.bg
    main.BorderSizePixel = 0
    main.ClipsDescendants = true
    main.Visible = false
    main.Parent = gui
    Instance.new("UICorner", main).CornerRadius = UDim.new(0, 12)

    local mainStroke = Instance.new("UIStroke")
    mainStroke.Color = COLORS.border
    mainStroke.Thickness = 1.2
    mainStroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
    mainStroke.Parent = main

    -- Animated Hex-Wave Background (inset cleanly inside the rounded corners)
    local hexBg = Instance.new("Frame")
    hexBg.Name = "HexBackground"
    hexBg.Size = UDim2.new(1, -12, 1, -12)
    hexBg.Position = UDim2.new(0, 6, 0, 6)
    hexBg.BackgroundTransparency = 1
    hexBg.ZIndex = 0
    hexBg.ClipsDescendants = true
    hexBg.Parent = main

    local HEX_CHARS = { "0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f" }
    local function randomHexLine(len)
        local t = table.create(len)
        for i = 1, len do
            t[i] = HEX_CHARS[math.random(1, 16)]
        end
        return table.concat(t, " ")
    end

    local hexRows = {}
    local ROW_COUNT = 26
    for r = 1, ROW_COUNT do
        local row = Instance.new("TextLabel")
        row.Name = "HexRow" .. r
        row.Size = UDim2.new(1, 0, 0, 20)
        row.Position = UDim2.new(0, 0, 0, (r - 1) * 20)
        row.BackgroundTransparency = 1
        row.Font = FONT_MONO
        row.TextSize = 13
        row.TextColor3 = Color3.new(1, 1, 1)
        row.TextTransparency = 0.25
        row.TextXAlignment = Enum.TextXAlignment.Left
        row.Text = randomHexLine(26)
        row.ZIndex = 0
        row.Parent = hexBg

        local grad = Instance.new("UIGradient")
        grad.Color = ColorSequence.new({
            ColorSequenceKeypoint.new(0.00, COLORS.hexDim),
            ColorSequenceKeypoint.new(0.32, COLORS.hexDim),
            ColorSequenceKeypoint.new(0.45, COLORS.blueGlow),
            ColorSequenceKeypoint.new(0.52, COLORS.hexWhite),
            ColorSequenceKeypoint.new(0.59, COLORS.blueAccent),
            ColorSequenceKeypoint.new(0.72, COLORS.hexDim),
            ColorSequenceKeypoint.new(1.00, COLORS.hexDim),
        })
        grad.Rotation = 18
        grad.Parent = row

        table.insert(hexRows, { label = row, grad = grad, phase = r * 0.22 })
    end

    -- Vignette with matching UICorner so nothing pokes out of rounded edges
    local vignette = Instance.new("Frame")
    vignette.Size = UDim2.new(1, 0, 1, 0)
    vignette.BackgroundColor3 = COLORS.bg
    vignette.BackgroundTransparency = 0.35
    vignette.BorderSizePixel = 0
    vignette.ZIndex = 1
    vignette.Parent = main
    Instance.new("UICorner", vignette).CornerRadius = UDim.new(0, 12)

    local content = Instance.new("Frame")
    content.Name = "Content"
    content.Size = UDim2.new(1, 0, 1, 0)
    content.BackgroundTransparency = 1
    content.ZIndex = 2
    content.Parent = main

    -- Title bar
    local titleBar = Instance.new("Frame")
    titleBar.Name = "TitleBar"
    titleBar.Size = UDim2.new(1, 0, 0, 46)
    titleBar.BackgroundTransparency = 1
    titleBar.ZIndex = 2
    titleBar.Parent = content

    local titleLabel = Instance.new("TextLabel")
    titleLabel.Name = "Title"
    titleLabel.Size = UDim2.new(1, -90, 1, 0)
    titleLabel.Position = UDim2.new(0, 16, 0, 0)
    titleLabel.BackgroundTransparency = 1
    titleLabel.Text = "EMOTE CATALOG"
    titleLabel.Font = FONT_BOLD
    titleLabel.TextSize = 17
    titleLabel.TextColor3 = COLORS.text
    titleLabel.TextXAlignment = Enum.TextXAlignment.Left
    titleLabel.ZIndex = 2
    titleLabel.Parent = titleBar

    local keyHint = Instance.new("TextLabel")
    keyHint.Name = "KeyHint"
    keyHint.Size = UDim2.new(0, 42, 0, 24)
    keyHint.Position = UDim2.new(1, -56, 0.5, -12)
    keyHint.BackgroundColor3 = COLORS.surface
    keyHint.BackgroundTransparency = 0.15
    keyHint.BorderSizePixel = 0
    keyHint.Text = "F5"
    keyHint.Font = FONT_BOLD
    keyHint.TextSize = 12
    keyHint.TextColor3 = COLORS.text
    keyHint.ZIndex = 2
    keyHint.Parent = titleBar
    Instance.new("UICorner", keyHint).CornerRadius = UDim.new(0, 6)
    local khStroke = Instance.new("UIStroke")
    khStroke.Color = COLORS.border
    khStroke.Thickness = 1
    khStroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
    khStroke.Parent = keyHint

    local divider = Instance.new("Frame")
    divider.Size = UDim2.new(1, -28, 0, 1)
    divider.Position = UDim2.new(0, 14, 0, 46)
    divider.BackgroundColor3 = COLORS.border
    divider.BackgroundTransparency = 0.2
    divider.BorderSizePixel = 0
    divider.ZIndex = 2
    divider.Parent = content

    -- Search bar
    local searchFrame = Instance.new("Frame")
    searchFrame.Name = "SearchFrame"
    searchFrame.Size = UDim2.new(1, -28, 0, 36)
    searchFrame.Position = UDim2.new(0, 14, 0, 56)
    searchFrame.BackgroundColor3 = COLORS.surface
    searchFrame.BackgroundTransparency = 0.15
    searchFrame.BorderSizePixel = 0
    searchFrame.ZIndex = 2
    searchFrame.Parent = content
    Instance.new("UICorner", searchFrame).CornerRadius = UDim.new(0, 8)
    local sfStroke = Instance.new("UIStroke")
    sfStroke.Color = COLORS.border
    sfStroke.Thickness = 1
    sfStroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
    sfStroke.Parent = searchFrame

    local searchBox = Instance.new("TextBox")
    searchBox.Name = "SearchBox"
    searchBox.Size = UDim2.new(1, -24, 1, 0)
    searchBox.Position = UDim2.new(0, 12, 0, 0)
    searchBox.BackgroundTransparency = 1
    searchBox.PlaceholderText = "Search Roblox emote catalog..."
    searchBox.PlaceholderColor3 = COLORS.subtext
    searchBox.Text = ""
    searchBox.Font = FONT_REGULAR
    searchBox.TextSize = 14
    searchBox.TextColor3 = COLORS.text
    searchBox.TextXAlignment = Enum.TextXAlignment.Left
    searchBox.ClearTextOnFocus = false
    searchBox.ZIndex = 2
    searchBox.Parent = searchFrame

    -- Sort tabs
    local catFrame = Instance.new("ScrollingFrame")
    catFrame.Name = "Categories"
    catFrame.Size = UDim2.new(1, -28, 0, 32)
    catFrame.Position = UDim2.new(0, 14, 0, 99)
    catFrame.BackgroundTransparency = 1
    catFrame.BorderSizePixel = 0
    catFrame.ScrollBarThickness = 0
    catFrame.ScrollingDirection = Enum.ScrollingDirection.X
    catFrame.AutomaticCanvasSize = Enum.AutomaticSize.X
    catFrame.CanvasSize = UDim2.new(0, 0, 0, 0)
    catFrame.ZIndex = 2
    catFrame.Parent = content

    local catLayout = Instance.new("UIListLayout")
    catLayout.FillDirection = Enum.FillDirection.Horizontal
    catLayout.VerticalAlignment = Enum.VerticalAlignment.Center
    catLayout.Padding = UDim.new(0, 6)
    catLayout.SortOrder = Enum.SortOrder.LayoutOrder
    catLayout.Parent = catFrame

    local catPad = Instance.new("UIPadding")
    catPad.PaddingLeft = UDim.new(0, 2)
    catPad.PaddingRight = UDim.new(0, 2)
    catPad.Parent = catFrame

    local currentSort = SORTS[1].sort
    local sortButtons = {}
    for i, sortInfo in ipairs(SORTS) do
        local isFirst = (i == 1)
        local btn = Instance.new("TextButton")
        btn.Name = sortInfo.label
        btn.Size = UDim2.new(0, 0, 0, 28)
        btn.AutomaticSize = Enum.AutomaticSize.X
        btn.BackgroundColor3 = isFirst and COLORS.whitePill or COLORS.surface
        btn.BackgroundTransparency = isFirst and 0 or 0.15
        btn.BorderSizePixel = 0
        btn.Text = sortInfo.label
        btn.Font = FONT_BOLD
        btn.TextSize = 13
        btn.TextColor3 = isFirst and COLORS.darkText or COLORS.subtext
        btn.LayoutOrder = i
        btn.ZIndex = 2
        btn.Parent = catFrame
        Instance.new("UICorner", btn).CornerRadius = UDim.new(0, 7)
        local bStroke = Instance.new("UIStroke")
        bStroke.Color = isFirst and COLORS.whitePill or COLORS.border
        bStroke.Thickness = 1
        bStroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
        bStroke.Parent = btn
        local pad = Instance.new("UIPadding")
        pad.PaddingLeft = UDim.new(0, 11)
        pad.PaddingRight = UDim.new(0, 11)
        pad.Parent = btn
        sortButtons[sortInfo.label] = { btn = btn, stroke = bStroke, sort = sortInfo.sort }
    end

    -- Emote grid (inset cleanly inside panel)
    local scrollFrame = Instance.new("ScrollingFrame")
    scrollFrame.Name = "EmoteGrid"
    scrollFrame.Size = UDim2.new(1, -24, 1, -152)
    scrollFrame.Position = UDim2.new(0, 12, 0, 138)
    scrollFrame.BackgroundTransparency = 1
    scrollFrame.BorderSizePixel = 0
    scrollFrame.ScrollBarThickness = 4
    scrollFrame.ScrollBarImageColor3 = COLORS.scrollbar
    scrollFrame.AutomaticCanvasSize = Enum.AutomaticSize.Y
    scrollFrame.CanvasSize = UDim2.new(0, 0, 0, 0)
    scrollFrame.ZIndex = 2
    scrollFrame.Parent = content

    local gridPad = Instance.new("UIPadding")
    gridPad.PaddingTop = UDim.new(0, 4)
    gridPad.PaddingBottom = UDim.new(0, 6)
    gridPad.Parent = scrollFrame

    local gridLayout = Instance.new("UIGridLayout")
    gridLayout.CellSize = UDim2.fromOffset(102, 136)
    gridLayout.CellPadding = UDim2.fromOffset(10, 10)
    gridLayout.SortOrder = Enum.SortOrder.LayoutOrder
    gridLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
    gridLayout.Parent = scrollFrame

    -- Now playing bar (floating rounded pill inside bottom edge)
    local nowPlaying = Instance.new("Frame")
    nowPlaying.Name = "NowPlaying"
    nowPlaying.Size = UDim2.new(1, -20, 0, 36)
    nowPlaying.Position = UDim2.new(0, 10, 1, -46)
    nowPlaying.BackgroundColor3 = COLORS.surface
    nowPlaying.BackgroundTransparency = 0.08
    nowPlaying.BorderSizePixel = 0
    nowPlaying.Visible = false
    nowPlaying.ZIndex = 3
    nowPlaying.Parent = content
    Instance.new("UICorner", nowPlaying).CornerRadius = UDim.new(0, 8)
    local npStroke = Instance.new("UIStroke")
    npStroke.Color = COLORS.border
    npStroke.Thickness = 1
    npStroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
    npStroke.Parent = nowPlaying

    local npLabel = Instance.new("TextLabel")
    npLabel.Size = UDim2.new(1, -78, 1, 0)
    npLabel.Position = UDim2.new(0, 12, 0, 0)
    npLabel.BackgroundTransparency = 1
    npLabel.Text = "Playing: ..."
    npLabel.Font = FONT_BOLD
    npLabel.TextSize = 13
    npLabel.TextColor3 = COLORS.blueAccent
    npLabel.TextXAlignment = Enum.TextXAlignment.Left
    npLabel.TextTruncate = Enum.TextTruncate.AtEnd
    npLabel.ZIndex = 3
    npLabel.Parent = nowPlaying

    local stopBtn = Instance.new("TextButton")
    stopBtn.Size = UDim2.new(0, 54, 0, 24)
    stopBtn.Position = UDim2.new(1, -62, 0.5, -12)
    stopBtn.BackgroundColor3 = COLORS.whitePill
    stopBtn.BorderSizePixel = 0
    stopBtn.Text = "Stop"
    stopBtn.Font = FONT_BOLD
    stopBtn.TextSize = 12
    stopBtn.TextColor3 = COLORS.darkText
    stopBtn.ZIndex = 3
    stopBtn.Parent = nowPlaying
    Instance.new("UICorner", stopBtn).CornerRadius = UDim.new(0, 6)

    local function getR15PreviewRig()
        local char = player and player.Character
        if char and char:FindFirstChildOfClass("Humanoid") then
            local wasArch = char.Archivable
            char.Archivable = true
            local clone = char:Clone()
            char.Archivable = wasArch
            if clone then
                for _, desc in ipairs(clone:GetDescendants()) do
                    if desc:IsA("Script") or desc:IsA("LocalScript") or desc:IsA("ModuleScript")
                        or desc:IsA("Sound") or desc:IsA("ForceField") then
                        desc:Destroy()
                    elseif desc:IsA("BasePart") then
                        desc.Anchored = false
                        desc.CanCollide = false
                    end
                end
                local hrp = clone:FindFirstChild("HumanoidRootPart")
                if hrp then hrp.Anchored = true end
                local hum = clone:FindFirstChildOfClass("Humanoid")
                if hum then
                    hum.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
                    hum.HealthDisplayType = Enum.HumanoidHealthDisplayType.AlwaysOff
                end
                return clone
            end
        end
        return nil
    end

    local animCache = {}
    local function resolveAnimId(catalogId)
        if animCache[catalogId] then
            return animCache[catalogId]
        end
        local okObj, objs = pcall(function()
            return game:GetObjects("rbxassetid://" .. catalogId)
        end)
        if okObj and objs and objs[1] then
            local root = objs[1]
            local anim = root:IsA("Animation") and root or root:FindFirstChildOfClass("Animation", true)
            if anim and anim.AnimationId ~= "" then
                animCache[catalogId] = anim.AnimationId
                return anim.AnimationId
            end
        end
        return nil
    end

    local currentlyPlayingCard = nil
    local activeTrack = nil

    local function stopCurrentEmote()
        if activeTrack then
            pcall(function() activeTrack:Stop() end)
            activeTrack = nil
        end
        if currentlyPlayingCard and currentlyPlayingCard.Parent then
            local oldStroke = currentlyPlayingCard:FindFirstChildOfClass("UIStroke")
            if oldStroke then
                TweenService:Create(oldStroke, TweenInfo.new(0.2), {Color = COLORS.border}):Play()
            end
        end
        currentlyPlayingCard = nil
        nowPlaying.Visible = false
        scrollFrame.Size = UDim2.new(1, -24, 1, -152)
    end

    stopBtn.MouseButton1Click:Connect(stopCurrentEmote)

    local cardCounter = 0
    local function createCatalogCard(item)
        cardCounter = cardCounter + 1
        local card = Instance.new("Frame")
        card.Name = item.Name or ("Emote_" .. tostring(item.Id))
        card.BackgroundColor3 = COLORS.card
        card.BackgroundTransparency = 0.22
        card.BorderSizePixel = 0
        card.LayoutOrder = cardCounter
        card.ZIndex = 2
        card.Parent = scrollFrame
        Instance.new("UICorner", card).CornerRadius = UDim.new(0, 9)

        local cardStroke = Instance.new("UIStroke")
        cardStroke.Color = COLORS.border
        cardStroke.Thickness = 1
        cardStroke.ApplyStrokeMode = Enum.ApplyStrokeMode.Border
        cardStroke.Parent = card

        local previewBox = Instance.new("Frame")
        previewBox.Name = "PreviewBox"
        previewBox.Size = UDim2.new(1, -12, 0, 78)
        previewBox.Position = UDim2.new(0, 6, 0, 6)
        previewBox.BackgroundColor3 = Color3.fromRGB(9, 10, 14)
        previewBox.BackgroundTransparency = 0.2
        previewBox.BorderSizePixel = 0
        previewBox.ClipsDescendants = true
        previewBox.ZIndex = 2
        previewBox.Parent = card
        Instance.new("UICorner", previewBox).CornerRadius = UDim.new(0, 7)

        local thumb = Instance.new("ImageLabel")
        thumb.Name = "Thumb"
        thumb.Size = UDim2.new(1, 0, 1, 0)
        thumb.BackgroundTransparency = 1
        thumb.ScaleType = Enum.ScaleType.Fit
        thumb.Image = "rbxthumb://type=Asset&id=" .. tostring(item.Id) .. "&w=150&h=150"
        thumb.ZIndex = 2
        thumb.Parent = previewBox

        local previewStarted = false
        local function startR15Preview()
            if previewStarted then return end
            previewStarted = true
            task.spawn(function()
                local animId = resolveAnimId(item.Id)
                local rig = getR15PreviewRig()
                if not animId or not rig or not card.Parent then return end

                local viewport = Instance.new("ViewportFrame")
                viewport.Name = "Preview"
                viewport.Size = UDim2.new(1, 0, 1, 0)
                viewport.BackgroundTransparency = 1
                viewport.BorderSizePixel = 0
                viewport.Ambient = Color3.fromRGB(165, 175, 195)
                viewport.LightColor = Color3.fromRGB(255, 255, 255)
                viewport.LightDirection = Vector3.new(-1, -1, 1)
                viewport.ZIndex = 2
                viewport.Parent = previewBox

                local worldModel = Instance.new("WorldModel")
                worldModel.Parent = viewport

                local cam = Instance.new("Camera")
                cam.CFrame = CFrame.new(Vector3.new(0, 0.4, -5.8), Vector3.new(0, 0.2, 0))
                cam.FieldOfView = 38
                cam.Parent = viewport
                viewport.CurrentCamera = cam

                rig:PivotTo(CFrame.new(0, 0, 0))
                rig.Parent = worldModel

                pcall(function()
                    local hum = rig:FindFirstChildOfClass("Humanoid")
                    local animator = hum:FindFirstChildOfClass("Animator") or Instance.new("Animator", hum)
                    local anim = Instance.new("Animation")
                    anim.AnimationId = animId
                    local track = animator:LoadAnimation(anim)
                    track.Looped = true
                    track:Play()
                end)

                thumb.Visible = false
            end)
        end

        local nameLabel = Instance.new("TextLabel")
        nameLabel.Name = "EmoteName"
        nameLabel.Size = UDim2.new(1, -8, 0, 20)
        nameLabel.Position = UDim2.new(0, 4, 0, 88)
        nameLabel.BackgroundTransparency = 1
        nameLabel.Text = item.Name or "Emote"
        nameLabel.Font = FONT_MEDIUM
        nameLabel.TextSize = 13
        nameLabel.TextColor3 = COLORS.text
        nameLabel.TextTruncate = Enum.TextTruncate.AtEnd
        nameLabel.ZIndex = 2
        nameLabel.Parent = card

        local priceText = (item.Price and item.Price > 0) and ("R$ " .. tostring(item.Price)) or "Free"
        local subLabel = Instance.new("TextLabel")
        subLabel.Name = "SubLabel"
        subLabel.Size = UDim2.new(1, -8, 0, 16)
        subLabel.Position = UDim2.new(0, 4, 0, 109)
        subLabel.BackgroundTransparency = 1
        subLabel.Text = priceText
        subLabel.Font = FONT_REGULAR
        subLabel.TextSize = 12
        subLabel.TextColor3 = COLORS.subtext
        subLabel.ZIndex = 2
        subLabel.Parent = card

        local clickBtn = Instance.new("TextButton")
        clickBtn.Name = "ClickArea"
        clickBtn.Size = UDim2.new(1, 0, 1, 0)
        clickBtn.BackgroundTransparency = 1
        clickBtn.Text = ""
        clickBtn.ZIndex = 3
        clickBtn.Parent = card

        clickBtn.MouseEnter:Connect(function()
            startR15Preview()
            TweenService:Create(cardStroke, TweenInfo.new(0.15), {Color = COLORS.borderHover}):Play()
        end)

        clickBtn.MouseLeave:Connect(function()
            local isPlaying = (currentlyPlayingCard == card)
            TweenService:Create(cardStroke, TweenInfo.new(0.15), {Color = isPlaying and COLORS.blueAccent or COLORS.border}):Play()
        end)

        clickBtn.MouseButton1Click:Connect(function()
            startR15Preview()
            if currentlyPlayingCard == card then
                stopCurrentEmote()
                return
            end

            stopCurrentEmote()
            currentlyPlayingCard = card
            TweenService:Create(cardStroke, TweenInfo.new(0.15), {Color = COLORS.blueAccent}):Play()

            nowPlaying.Visible = true
            npLabel.Text = "Playing: " .. (item.Name or "Emote")
            scrollFrame.Size = UDim2.new(1, -24, 1, -196)

            task.spawn(function()
                local animId = resolveAnimId(item.Id)
                if not animId then return end
                pcall(function()
                    local char = player.Character
                    if not char then return end
                    local hum = char:FindFirstChildOfClass("Humanoid")
                    if not hum then return end
                    local animator = hum:FindFirstChildOfClass("Animator") or Instance.new("Animator", hum)
                    local anim = Instance.new("Animation")
                    anim.AnimationId = animId
                    local track = animator:LoadAnimation(anim)
                    track.Priority = Enum.AnimationPriority.Action4
                    track.Looped = true
                    track:Play()
                    activeTrack = track
                end)
            end)
        end)
    end

    -- Dynamic Catalog Query Engine
    local queryToken = 0
    local currentPages = nil
    local isLoadingPage = false

    local function clearGrid()
        for _, child in ipairs(scrollFrame:GetChildren()) do
            if child:IsA("Frame") then
                child:Destroy()
            end
        end
        cardCounter = 0
        currentlyPlayingCard = nil
    end

    local function loadNextPage(token)
        if isLoadingPage or not currentPages or token ~= queryToken then return end
        isLoadingPage = true

        task.spawn(function()
            local page = currentPages:GetCurrentPage()
            if token ~= queryToken then
                isLoadingPage = false
                return
            end
            for _, item in ipairs(page) do
                if token ~= queryToken then break end
                createCatalogCard(item)
            end

            if not currentPages.IsFinished and token == queryToken then
                pcall(function() currentPages:AdvanceToNextPageAsync() end)
            else
                currentPages = nil
            end
            isLoadingPage = false
        end)
    end

    local function startCatalogQuery(keyword, sortType)
        queryToken = queryToken + 1
        local token = queryToken
        isLoadingPage = false
        currentPages = nil
        clearGrid()
        scrollFrame.CanvasPosition = Vector2.new(0, 0)

        task.spawn(function()
            local okCat, pages = pcall(function()
                local p = CatalogSearchParams.new()
                p.AssetTypes = { Enum.AvatarAssetType.EmoteAnimation }
                p.SortType = sortType
                p.Limit = 120
                if keyword and keyword ~= "" then
                    p.SearchKeyword = keyword
                end
                return AvatarEditorService:SearchCatalog(p)
            end)
            if token ~= queryToken then return end
            if okCat and pages then
                currentPages = pages
                loadNextPage(token)
                task.wait(0.2)
                if token == queryToken and currentPages then
                    loadNextPage(token)
                end
            end
        end)
    end

    scrollFrame:GetPropertyChangedSignal("CanvasPosition"):Connect(function()
        if currentPages and not isLoadingPage then
            local maxY = math.max(0, scrollFrame.AbsoluteCanvasSize.Y - scrollFrame.AbsoluteWindowSize.Y)
            if maxY > 0 and scrollFrame.CanvasPosition.Y >= maxY - 300 then
                loadNextPage(queryToken)
            end
        end
    end)

    local searchSerial = 0
    searchBox:GetPropertyChangedSignal("Text"):Connect(function()
        searchSerial = searchSerial + 1
        local mySerial = searchSerial
        task.delay(0.35, function()
            if mySerial == searchSerial then
                startCatalogQuery(searchBox.Text, currentSort)
            end
        end)
    end)

    for _, info in pairs(sortButtons) do
        info.btn.MouseButton1Click:Connect(function()
            currentSort = info.sort
            for _, other in pairs(sortButtons) do
                local isSel = (other.btn == info.btn)
                TweenService:Create(other.btn, TweenInfo.new(0.15), {
                    BackgroundColor3 = isSel and COLORS.whitePill or COLORS.surface,
                    BackgroundTransparency = isSel and 0 or 0.15,
                }):Play()
                TweenService:Create(other.stroke, TweenInfo.new(0.15), {
                    Color = isSel and COLORS.whitePill or COLORS.border,
                }):Play()
                other.btn.TextColor3 = isSel and COLORS.darkText or COLORS.subtext
            end
            startCatalogQuery(searchBox.Text, currentSort)
        end)
    end

    -- Animate hex-wave background when UI is visible
    local elapsed = 0
    local mutateAccum = 0
    RunService.RenderStepped:Connect(function(dt)
        if not gui.Parent or not main.Visible then return end
        elapsed = elapsed + dt
        mutateAccum = mutateAccum + dt

        for _, row in ipairs(hexRows) do
            local wave = math.sin(elapsed * 0.9 + row.phase) * 0.55
            row.grad.Offset = Vector2.new(wave, 0)
        end

        if mutateAccum >= 0.35 then
            mutateAccum = 0
            local pick = hexRows[math.random(1, #hexRows)]
            if pick then
                pick.label.Text = randomHexLine(26)
            end
        end
    end)

    -- F5 Toggle
    local uiOpen = false
    local function toggleUI()
        uiOpen = not uiOpen
        if uiOpen then
            main.Visible = true
            main.Size = UDim2.new(0, 368, 0, 0)
            main.BackgroundTransparency = 0.25
            TweenService:Create(main, TweenInfo.new(0.3, Enum.EasingStyle.Back, Enum.EasingDirection.Out), {
                Size = UDim2.new(0, 368, 0, 530),
                BackgroundTransparency = 0,
            }):Play()
        else
            local tween = TweenService:Create(main, TweenInfo.new(0.2, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {
                Size = UDim2.new(0, 368, 0, 0),
                BackgroundTransparency = 0.25,
            })
            tween:Play()
            tween.Completed:Connect(function()
                if not uiOpen then
                    main.Visible = false
                end
            end)
        end
    end

    UserInputService.InputBegan:Connect(function(input)
        if UserInputService:GetFocusedTextBox() then return end
        if input.KeyCode == Enum.KeyCode.F5 then
            toggleUI()
        end
    end)

    startCatalogQuery("", currentSort)
    print("Emote Catalog edges fixed! Press F5.")
end, debug.traceback)

if not ok then
    warn("EmoteHub error:", err)
end
Universal Script 🎭
undefined Emote Catalogue
395views
6 days ago

Emote Catalogue

Status
Working
Price
Free

Description

Emotes are paid, I find that annoying. Sooo I made an universal emote catalogue lads, so bye bye paid emotes. When you scroll on the UI, your fps might drop. A fix is gonna come in that later update

Update log:

Related Scripts