hi, im using a script to search a ui for items in it however, it doesnt search and still shows everything
script
script.Parent.Parent.SearchBox:GetPropertyChangedSignal(“Text”):Connect(function()
local S = script.Parent.Parent.SearchBox.Text
for _, SearchBox in pairs(script.Parent.Parent.Parent.SubCatalog.Holder:GetChildren()) do
if SearchBox:IsA("Frame") then
local searchName = SearchBox.Name
if S == "" or searchName:sub(1, #S):lower() == S:lower() then
SearchBox.Visible = true
else
SearchBox.Visible = false
end
end
end
if you want to sort items in a frame/scrolling frame, you should:
1- make a function that checks if you can find the text in the searchBar in any frames, and if so, it keeps it visible else it makes it invisible
2-then make the funciton fire everytime the searchBar changes
(Dont forget to change the variables to your current situation)
local searchBar = script.Parent:WaitForChild("SearchBar") -- Search Bar's location
local frame = script.Parent:WaitForChild("ScrollingFrame") -- ScrollingFrame or things you wanna sort's parent location
function updateResults()
local search = string.lower(searchbar.Text)
for i,v in pairs(frame:GetChildren()) do
if v:IsA("Frame") then
local sortFrame = v
if search ~= "" then
local searchedItem = string.lower(sortFrame.Name)
if string.find(searchedItem, search) then
v.Visible = true
else
v.Visible = false
end
else
v.Visible = true
end
end
end
end
searchbar.Changed:Connect(updateResults)