How would I make a search bar?

Hello,

I am working on a building system and I have a textbox where you can search for items.

Now how do I do that?

I know there are other posts about this including Fuzzy Search bars. But whenever I try all of them they wont work.

Thanks in advance.

You can iterate through all the items with a for-in loop, and then check if the item name has whatever is in the search bar, everytime it is changed (GetPropertyChangedSignal(“Text”)), by using string.find(). That would look something like this:

TextBox:GetPropertyChangedSignal("Text"):Connect(function()
    local text = TextBox.Text
    local validItems = {}
    for _,item in ipairs(...) do -- item table goes in ...
        local itemName = . -- ItemName goes here
        if itemName:find(text) then
            validItems[#validItems+1] = item
        end
    end
end)
1 Like

I have also tried Using :Disconnect() to prevent memory leaks, as you constantly connect to an event whenever the text changes.

But whenever I add :Disconnect() to the end it just works once and then if I change the text again it wont detect.

Do I need to use :Disconnect() to prevent Memory leaks in this sittuation, and if so where should I put ?

The thing you’re looking for is called Fuzzy Search there’re some topics about this. Regarding to your request, maybe this one could help you:

I tried that one. Does not work.

1 Like