I’m making a search bar for someone and it’s working nicely but also bring about some struggles. I’ll go a little more in depth:
When you remove each individual letter, it’ll restore all the items like usual. However, if you remove all of the text instantly, it’ll think nothing happened and keep everything hidden, saying the search didn’t match anything.
-- SEARCH --
box:GetPropertyChangedSignal('Text'):Connect(function()
sounds.LetterTyped:Play()
if box.Text:len() == 0 then -- if there is no input
tService:Create(scrolling, canvasPosInfo, {CanvasPosition = Vector2.new(0,0)}):Play()
noResults.Visible = false
for _, item in pairs(scrolling:GetChildren()) do
if item:IsA('TextButton') and not item:GetAttribute('unav') then
item.Visible = true
end
end
else -- if there is an input then try to start matching
for _, item in pairs(scrolling:GetChildren()) do
if item:IsA('TextButton') then
if string.match(item.AssetName.Text:lower(), box.Text:lower()) then
item.Visible = true
if table.find(hidden, item.AssetName.Text) then
local index = table.find(hidden, item.AssetName.Text)
table.remove(hidden, index)
end
elseif not string.match(item.AssetName.Text:lower(), box.Text:lower()) and item:IsA('TextButton') and not table.find(hidden, item.AssetName.Text) then
table.insert(hidden, item.AssetName.Text)
item.Visible = false
end
end
end
end
if #hidden == #scrolling:GetChildren() - 3 then
noResults.Visible = true
for _, item in pairs(scrolling:GetChildren()) do
if item:IsA('TextButton') then
item.Visible = false
end
end
else
noResults.Visible = false
end
end)