local ReplicatedStorage = game:GetService("ReplicatedStorage") local Players =…
- 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 categories = { {name = "Male", folder = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Male"), template = ReplicatedStorage:WaitForChild("ButtonTemplates"):WaitForChild("MaleTemplate"), list = Animation:WaitForChild("Men_List")}, {name = "Female", folder = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Female"), template = ReplicatedStorage:WaitForChild("ButtonTemplates"):WaitForChild("FemaleTemplate"), list = Animation:WaitForChild("Women_List")}, {name = "ThreePlus", folder = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("ThreePlus"), template = ReplicatedStorage:WaitForChild("ButtonTemplates"):WaitForChild("ThreePlusTemplate"), list = Animation:WaitForChild("Plus_List")}, {name = "Emote", folder = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Emotes"), template = ReplicatedStorage:WaitForChild("ButtonTemplates"):WaitForChild("EmoteTemplate"), list = Animation:WaitForChild("Emote_List")} }
local All_List = Animation:WaitForChild("All_List")
local function hideAllLists() for _, category in categories do category.list.Visible = false end All_List.Visible = false end
local function showList(list) hideAllLists() list.Visible = true end
local function setupButtons(category) for _, anim in category.folder:GetChildren() do local button = category.template:Clone() button.Name = anim.Name button.Text = anim.Name button.Parent = category.list
local allButton = button:Clone() allButton.Parent = All_List endend
for _, category in categories do setupButtons(category) end
local TitleLabel = script.Parent:WaitForChild("TitleLabel") local buttons = { ["+"] = {TitleLabel:WaitForChild("+"), function() showList(Animation:WaitForChild("Plus_List")) end}, ["ALL"] = {TitleLabel:WaitForChild("ALL"), function() showList(All_List) end}, ["E"] = {TitleLabel:WaitForChild("E"), function() showList(Animation:WaitForChild("Emote_List")) end}, ["M"] = {TitleLabel:WaitForChild("M"), function() showList(Animation:WaitForChild("Men_List")) end}, ["W"] = {TitleLabel:WaitForChild("W"), function() showList(Animation:WaitForChild("Women_List")) end} }
for _, buttonInfo in buttons do local button, callback = unpack(buttonInfo) button.MouseButton1Click:Connect(callback) end
The Searchbar is a Textbox. Whenever the player types in something, try and have the string to match the Animation name. For example, if the player writes "da" only, it should show all of the animations that start with "da" in the Animation frames.
- Assistant
To implement the search functionality in your script, we need to add an event listener for the
SearchbarTextBox to react to changes in the text entered by the user. Then we can filter the animations based on the text entered and display only the animations that match the search query.Here is an updated version of your script with the search functionality added:
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 categories = { {name = "Male", folder = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Male"), template = ReplicatedStorage:WaitForChild("ButtonTemplates"):WaitForChild("MaleTemplate"), list = Animation:WaitForChild("Men_List")}, {name = "Female", folder = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Female"), template = ReplicatedStorage:WaitForChild("ButtonTemplates"):WaitForChild("FemaleTemplate"), list = Animation:WaitForChild("Women_List")}, {name = "ThreePlus", folder = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("ThreePlus"), template = ReplicatedStorage:WaitForChild("ButtonTemplates"):WaitForChild("ThreePlusTemplate"), list = Animation:WaitForChild("Plus_List")}, {name = "Emote", folder = ReplicatedStorage:WaitForChild("Animations"):WaitForChild("Emotes"), template = ReplicatedStorage:WaitForChild("ButtonTemplates"):WaitForChild("EmoteTemplate"), list = Animation:WaitForChild("Emote_List")} } local All_List = Animation:WaitForChild("All_List") local function hideAllLists() for _, category in categories do category.list.Visible = false end All_List.Visible = false end local function showList(list) hideAllLists() list.Visible = true end local function setupButtons(category) for _, anim in category.folder:GetChildren() do local button = category.template:Clone() button.Name = anim.Name button.Text = anim.Name button.Parent = category.list local allButton = button:Clone() allButton.Parent = All_List end end for _, category in categories do setupButtons(category) end local TitleLabel = script.Parent:WaitForChild("TitleLabel") local buttons = { ["+"] = {TitleLabel:WaitForChild("+"), function() showList(Animation:WaitForChild("Plus_List")) end}, ["ALL"] = {TitleLabel:WaitForChild("ALL"), function() showList(All_List) end}, ["E"] = {TitleLabel:WaitForChild("E"), function() showList(Animation:WaitForChild("Emote_List")) end}, ["M"] = {TitleLabel:WaitForChild("M"), function() showList(Animation:WaitForChild("Men_List")) end}, ["W"] = {TitleLabel:WaitForChild("W"), function() showList(Animation:WaitForChild("Women_List")) end} } for _, buttonInfo in buttons do local button, callback = unpack(buttonInfo) button.MouseButton1Click:Connect(callback) end -- Function to filter the buttons based on the search query local function filterAnimations(query) local lowerQuery = query:lower() for _, category in categories do for _, button in category.list:GetChildren() do if button:IsA("GuiButton") then if button.Name:lower():find(lowerQuery) then button.Visible = true else button.Visible = false end end end end -- Filter the All_List as well for _, button in All_List:GetChildren() do if button:IsA("GuiButton") then if button.Name:lower():find(lowerQuery) then button.Visible = true else button.Visible = false end end end end -- Listen to changes in the Searchbar text Searchbar:GetPropertyChangedSignal("Text"):Connect(function() filterAnimations(Searchbar.Text) end)In this script, there is a new function
filterAnimationsthat is called whenever the text in theSearchbarchanges. This function filters the buttons in each animation list and theAll_Listto match the search query.To filter the animations, the function converts the query and animation names to lowercase (to make the search case-insensitive) and uses the
string.findmethod to check if the query is a substring of the animation name. If it is, the button is shown (button.Visible = true), otherwise it is hidden (button.Visible = false). - User
can you tell me what happens when the player deletes the text in the textbox?
- Assistant
When the player deletes the text in the
SearchbarTextBox, theTextproperty of theSearchbarbecomes an empty string (""). Given the current implementation of thefilterAnimationsfunction, the following sequence of events occurs:- The
Searchbar:GetPropertyChangedSignal("Text")event is triggered. - The
filterAnimationsfunction is called with an empty string as its parameter (sinceSearchbar.Textis now an empty string). - Inside the
filterAnimationsfunction, thelowerQueryvariable is set to the lowercase version of the empty string, which is still an empty string. - The function then iterates through all the buttons in each category's list and the
All_List.- For each button, it checks if the button's name (converted to lowercase) contains the
lowerQuery(which is an empty string) using thestring.findmethod. - Since every string in Lua contains the empty string, the condition
button.Name:lower():find(lowerQuery)will always evaluate totruewhenlowerQueryis an empty string. - As a result,
button.Visible = trueis executed for every button.
- For each button, it checks if the button's name (converted to lowercase) contains the
In effect, all the animation buttons will be made visible when the search bar is cleared. This ensures that after clearing the search bar, the player can see and access all available animations, which is typically the desired behavior for a search function.
Here is the relevant portion of the script for clarity:
local function filterAnimations(query) local lowerQuery = query:lower() for _, category in categories do for _, button in category.list:GetChildren() do if button:IsA("GuiButton") then if button.Name:lower():find(lowerQuery) then button.Visible = true else button.Visible = false end end end end -- Filter the All_List as well for _, button in All_List:GetChildren() do if button:IsA("GuiButton") then if button.Name:lower():find(lowerQuery) then button.Visible = true else button.Visible = false end end end end -- Listen to changes in the Searchbar text Searchbar:GetPropertyChangedSignal("Text"):Connect(function() filterAnimations(Searchbar.Text) end)This code correctly handles the scenario where the search bar is cleared, ensuring the player has a comprehensive view of all animations when the search field is empty.
- The