Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-2024-05-13· OpenAIAi2 WildChat-4.8M (AI2)

local Players = game:GetService("Players") local ReplicatedStorage =…

  1. User

    local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local ChatBypassEvent = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("ChatBypass") local ChatService = require(game.ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService")) local ServerStorage = game:GetService("ServerStorage")

    local getAnimationsFunction = ReplicatedStorage:WaitForChild("RemoteFunctions"):WaitForChild("GetAnimations")

    local categories = { {name = "Male", folder = ServerStorage:WaitForChild("Animations"):WaitForChild("Male")}, {name = "Female", folder = ServerStorage:WaitForChild("Animations"):WaitForChild("Female")}, {name = "ThreePlus", folder = ServerStorage:WaitForChild("Animations"):WaitForChild("ThreePlus")}, {name = "Emote", folder = ServerStorage:WaitForChild("Animations"):WaitForChild("Emotes")} }

    local animations = {}

    local function getAnimations() for _, category in categories do local animList = {} for _, anim in category.folder:GetChildren() do table.insert(animList, anim.Name) end animations[category.name] = animList end return animations end

    local function getMorphs() -- Dummy function for demonstration purposes. -- Replace this with actual morph retrieval logic. return {"Morph1", "Morph2", "Morph3"} end

    getAnimationsFunction.OnServerInvoke = function(player, requestType) if requestType == "animation" then return getAnimations() elseif requestType == "morph" then return getMorphs() else return nil end end

    the animations in ThreePlus will have an attribute called 'Gender' followed by a letter: 'M' or 'F'. how do i also send that?

  2. Assistant

    To include the 'Gender' attribute in the animations for the "ThreePlus" category, you'll need to modify the getAnimations function to check for this attribute and include it in the returned data. Below is the modified code that incorporates this feature:

    local Players = game:GetService("Players")
    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local ChatBypassEvent = ReplicatedStorage:WaitForChild("RemoteEvents"):WaitForChild("ChatBypass")
    local ChatService = require(game.ServerScriptService:WaitForChild("ChatServiceRunner"):WaitForChild("ChatService"))
    local ServerStorage = game:GetService("ServerStorage")
    
    local getAnimationsFunction = ReplicatedStorage:WaitForChild("RemoteFunctions"):WaitForChild("GetAnimations")
    
    local categories = {
        {name = "Male", folder = ServerStorage:WaitForChild("Animations"):WaitForChild("Male")},
        {name = "Female", folder = ServerStorage:WaitForChild("Animations"):WaitForChild("Female")},
        {name = "ThreePlus", folder = ServerStorage:WaitForChild("Animations"):WaitForChild("ThreePlus")},
        {name = "Emote", folder = ServerStorage:WaitForChild("Animations"):WaitForChild("Emotes")}
    }
    
    local animations = {}
    
    local function getAnimations()
        for _, category in categories do
            local animList = {}
            for _, anim in category.folder:GetChildren() do
                if category.name == "ThreePlus" then
                    -- Check if the animation has a 'Gender' attribute
                    local gender = anim:GetAttribute("Gender")
                    if gender then
                        table.insert(animList, {Name = anim.Name, Gender = gender})
                    else
                        table.insert(animList, {Name = anim.Name})
                    end
                else
                    table.insert(animList, anim.Name)
                end
            end
            animations[category.name] = animList
        end
        return animations
    end
    
    local function getMorphs()
        -- Dummy function for demonstration purposes.
        -- Replace this with actual morph retrieval logic.
        return {"Morph1", "Morph2", "Morph3"}
    end
    
    getAnimationsFunction.OnServerInvoke = function(player, requestType)
        if requestType == "animation" then
            return getAnimations()
        elseif requestType == "morph" then
            return getMorphs()
        else
            return nil
        end
    end
    

    In this updated code, when processing the "ThreePlus" category, the code checks if the animation has a 'Gender' attribute and includes it in the returned data if it exists. If there is no 'Gender' attribute, only the animation name is added to the list. For other categories, it simply adds the animation name as before. This way, the function will return the additional 'Gender' information for the animations in the "ThreePlus" category.

  3. User

    local ReplicatedStorage = game:GetService("ReplicatedStorage") local Players = game:GetService("Players") local localPlayer = Players.LocalPlayer local PlayerGui = localPlayer:WaitForChild("PlayerGui") local MainMenuGui = PlayerGui:WaitForChild("MainMenuGui") local MainFrame = MainMenuGui:WaitForChild("MainFrame") local Animation = MainFrame:WaitForChild("Animation") local Searchbar = Animation:WaitForChild("Searchbar") local AnimAPI = ReplicatedStorage:WaitForChild("LocalScriptAPI") local AnimSpeedRemote = AnimAPI:WaitForChild("AnimSpeed") local Char = localPlayer.Character or localPlayer.CharacterAdded:Wait() local TitleLabel = script.Parent:WaitForChild("TitleLabel")

    local playingAnim = false local debounce = true local debouncedTime = 1

    local BUTTON_COLORS = { Male = Color3.fromRGB(170, 170, 255), Female = Color3.fromRGB(255, 185, 255), }

    local categories = { {name = "Male", template = "MaleTemplate", list = "Men_List"}, {name = "Female", template = "FemaleTemplate", list = "Women_List"}, {name = "ThreePlus", template = "ThreePlusTemplate", list = "Plus_List"}, {name = "Emote", template = "EmoteTemplate", list = "Emote_List"} }

    local function getInstance(path) local success, instance = pcall(ReplicatedStorage.WaitForChild, ReplicatedStorage, path) if not success then error("Error! Instance not found: " .. path) end return instance end

    local function onButtonClick(button) if not debounce then return end debounce = false

    if playingAnim then
    	AnimAPI.StopAnimationOnHumanoid:FireServer(Char.Humanoid)
    else
    	AnimAPI.PlayAnimation:InvokeServer(button.Name, Char)
    end
    
    playingAnim = not playingAnim
    task.delay(debouncedTime, function()
    	debounce = true
    end)
    

    end

    local function hideAllLists() for _, category in ipairs(categories) do local listInstance = Animation:WaitForChild(category.list) listInstance.Visible = false end Animation:WaitForChild("All_List").Visible = false end

    local function showList(list) hideAllLists() list.Visible = true end

    local function createButton(template, parent, animName, color) local button = template:Clone() button.Name = animName button.Text = animName if color then button.TextColor3 = color end button.Parent = parent button.MouseButton1Click:Connect(function() onButtonClick(button) end) return button end

    local function setupButtons(category, animNames) local template = getInstance("ButtonTemplates"):WaitForChild(category.template) local listInstance = Animation:WaitForChild(category.list)

    for _, animName in ipairs(animNames) do
    	if category.name == "ThreePlus" then
    		local gender = template:GetAttribute("Gender")
    		print(gender)
    		local color = BUTTON_COLORS[gender] or nil
    		createButton(template, listInstance, animName, color)
    		createButton(template, Animation:WaitForChild("All_List"), animName, color)
    	else
    		createButton(template, listInstance, animName)
    		createButton(template, Animation:WaitForChild("All_List"), animName)
    	end
    end
    

    end

    local getAnimationsFunction = getInstance("RemoteFunctions"):WaitForChild("GetAnimations") local animationsData = getAnimationsFunction:InvokeServer("animation")

    for categoryName, animNames in pairs(animationsData) do for _, category in ipairs(categories) do if category.name == categoryName then setupButtons(category, animNames) break end end end

    local buttons = { {Name = "+", Action = function() showList(Animation:WaitForChild("Plus_List")) end}, {Name = "ALL", Action = function() showList(Animation:WaitForChild("All_List")) end}, {Name = "E", Action = function() showList(Animation:WaitForChild("Emote_List")) end}, {Name = "M", Action = function() showList(Animation:WaitForChild("Men_List")) end}, {Name = "W", Action = function() showList(Animation:WaitForChild("Women_List")) end} }

    for _, buttonInfo in ipairs(buttons) do local button = TitleLabel:WaitForChild(buttonInfo.Name) button.MouseButton1Click:Connect(buttonInfo.Action) end

    local function filterAnimations(query) local lowerQuery = query:lower() local function toggleVisibility(button) button.Visible = button.Name:lower():find(lowerQuery) ~= nil end

    for _, category in ipairs(categories) do
    	for _, button in ipairs(category.list:GetChildren()) do
    		if button:IsA("GuiButton") then
    			toggleVisibility(button)
    		end
    	end
    end
    
    for _, button in ipairs(Animation:WaitForChild("All_List"):GetChildren()) do
    	if button:IsA("GuiButton") then
    		toggleVisibility(button)
    	end
    end
    

    end

    Searchbar:GetPropertyChangedSignal("Text"):Connect(function() filterAnimations(Searchbar.Text) end)

    how do i update this localscript code to change the button text's color based on the sent attribute?

  4. Assistant

    To update the LocalScript to change the button text's color based on the sent attribute (Gender), you'll need to update the setupButtons function to check for the attribute in the animNames list when dealing with the "ThreePlus" category. We need to modify how animNames are structured when received from the server to include both the Name and Gender attributes for the "ThreePlus" category animations.

    Here is the updated code:

    Server Script (Minor Update)

    local function getAnimations()
        for _, category in categories do
            local animList = {}
            for _, anim in category.folder:GetChildren() do
                if category.name == "ThreePlus" then
                    local gender = anim:GetAttribute("Gender")
                    if gender then
                        table.insert(animList, {Name = anim.Name, Gender = gender})
                    else
                        table.insert(animList, {Name = anim.Name})
                    end
                else
                    table.insert(animList, anim.Name)
                end
            end
            animations[category.name] = animList
        end
        return animations
    end
    

    LocalScript (Updated)

    local ReplicatedStorage = game:GetService("ReplicatedStorage")
    local Players = game:GetService("Players")
    local localPlayer = Players.LocalPlayer
    local PlayerGui = localPlayer:WaitForChild("PlayerGui")
    local MainMenuGui = PlayerGui:WaitForChild("MainMenuGui")
    local MainFrame = MainMenuGui:WaitForChild("MainFrame")
    local Animation = MainFrame:WaitForChild("Animation")
    local Searchbar = Animation:WaitForChild("Searchbar")
    local AnimAPI = ReplicatedStorage:WaitForChild("LocalScriptAPI")
    local AnimSpeedRemote = AnimAPI:WaitForChild("AnimSpeed")
    local Char = localPlayer.Character or localPlayer.CharacterAdded:Wait()
    local TitleLabel = script.Parent:WaitForChild("TitleLabel")
    
    local playingAnim = false
    local debounce = true
    local debouncedTime = 1
    
    local BUTTON_COLORS = {
        M = Color3.fromRGB(170, 170, 255),
        F = Color3.fromRGB(255, 185, 255),
    }
    
    local categories = {
        {name = "Male", template = "MaleTemplate", list = "Men_List"},
        {name = "Female", template = "FemaleTemplate", list = "Women_List"},
        {name = "ThreePlus", template = "ThreePlusTemplate", list = "Plus_List"},
        {name = "Emote", template = "EmoteTemplate", list = "Emote_List"}
    }
    
    local function getInstance(path)
        local success, instance = pcall(ReplicatedStorage.WaitForChild, ReplicatedStorage, path)
        if not success then
            error("Error! Instance not found: " .. path)
        end
        return instance
    end
    
    local function onButtonClick(button)
        if not debounce then return end
        debounce = false
    
        if playingAnim then
            AnimAPI.StopAnimationOnHumanoid:FireServer(Char.Humanoid)
        else
            AnimAPI.PlayAnimation:InvokeServer(button.Name, Char)
        end
    
        playingAnim = not playingAnim
        task.delay(debouncedTime, function()
            debounce = true
        end)
    end
    
    local function hideAllLists()
        for _, category in ipairs(categories) do
            local listInstance = Animation:WaitForChild(category.list)
            listInstance.Visible = false
        end
        Animation:WaitForChild("All_List").Visible = false
    end
    
    local function showList(list)
        hideAllLists()
        list.Visible = true
    end
    
    local function createButton(template, parent, animName, color)
        local button = template:Clone()
        button.Name = animName
        button.Text = animName
        if color then
            button.TextColor3 = color
        end
        button.Parent = parent
        button.MouseButton1Click:Connect(function()
            onButtonClick(button)
        end)
        return button
    end
    
    local function setupButtons(category, animList)
        local template = getInstance("ButtonTemplates"):WaitForChild(category.template)
        local listInstance = Animation:WaitForChild(category.list)
    
        for _, animData in ipairs(animList) do
            if type(animData) == "table" and animData.Name and animData.Gender then
                -- For ThreePlus category where animData is a table with Name and Gender
                local color = BUTTON_COLORS[animData.Gender] or nil
                createButton(template, listInstance, animData.Name, color)
                createButton(template, Animation:WaitForChild("All_List"), animData.Name, color)
            else
                -- For other categories where animData is just a name
                createButton(template, listInstance, animData)
                createButton(template, Animation:WaitForChild("All_List"), animData)
            end
        end
    end
    
    local getAnimationsFunction = getInstance("RemoteFunctions"):WaitForChild("GetAnimations")
    local animationsData = getAnimationsFunction:InvokeServer("animation")
    
    for categoryName, animList in pairs(animationsData) do
        for _, category in ipairs(categories) do
            if category.name == categoryName then
                setupButtons(category, animList)
                break
            end
        end
    end
    
    local buttons = {
        {Name = "+", Action = function() showList(Animation:WaitForChild("Plus_List")) end},
        {Name = "ALL", Action = function() showList(Animation:WaitForChild("All_List")) end},
        {Name = "E", Action = function() showList(Animation:WaitForChild("Emote_List")) end},
        {Name = "M", Action = function() showList(Animation:WaitForChild("Men_List")) end},
        {Name = "W", Action = function() showList(Animation:WaitForChild("Women_List")) end}
    }
    
    for _, buttonInfo in ipairs(buttons) do
        local button = TitleLabel:WaitForChild(buttonInfo.Name)
        button.MouseButton1Click:Connect(buttonInfo.Action)
    end
    
    local function filterAnimations(query)
        local lowerQuery = query:lower()
        local function toggleVisibility(button)
            button.Visible = button.Name:lower():find(lowerQuery) ~= nil
        end
    
        for _, category in ipairs(categories) do
            for _, button in ipairs(Animation:WaitForChild(category.list):GetChildren()) do
                if button:IsA("GuiButton") then
                    toggleVisibility(button)
                end
            end
        end
    
        for _, button in ipairs(Animation:WaitForChild("All_List"):GetChildren()) do
            if button:IsA("GuiButton") then
                toggleVisibility(button)
            end
        end
    end
    
    Searchbar:GetPropertyChangedSignal("Text"):Connect(function()
        filterAnimations(Searchbar.Text)
    end)
    

    Here's what's been updated:

    1. Button Text Color Based on Gender:

      • When creating buttons for the "ThreePlus" category, check the Gender attribute and set the button text color based on BUTTON_COLORS.
    2. Handling the Animations Data:

      • When receiving the animationsData from the server, the "ThreePlus" category animations now include a table with both Name and Gender.
    3. Dynamic Button Creation:

      • Updated the createButton function to accept a text color and apply it to the button text color.
      • Adjusted the setupButtons function to handle both cases where animList items are strings or tables containing Name and Gender.
    4. Ensure Filtering Works Smoothly:

      • Made sure filterAnimations works properly by toggling the visibility of buttons based on their names matching the search query.

    The provided solution ensures that the text color of buttons for animations in the "ThreePlus" category changes according to the specified gender attribute.