Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I have a problem with my search bar, could anyone help?

Asked by 4 years ago
Edited 4 years ago

I'm creating a search bar in my Gui and I wanted to add a feature where you can search for multiple string of text my separating them with commas and it keeps returning this error at line 21: attempt to index field '?' (a nil value)

This is the full script:

SearchBar = script.Parent
Input = SearchBar.Input
Items = SearchBar.Parent.Items

Input:GetPropertyChangedSignal("Text"):Connect(function()
    if Input.Text:match(",") == nil then
        for i,v in pairs(Items:GetChildren()) do
            if v:IsA("TextLabel") then
                if v.Name:lower():find(Input.Text:lower()) then
                    v.Visible = true
                else
                    v.Visible = false
                end
            end
        end
    else
        local SearchFor = Input.Text:split("," or ", ")
        for i = 1, #SearchFor do
            for i,v in pairs(Items:GetChildren()) do
                if not v:IsA("UIListLayout")  then
                    if v.Name:lower():match(SearchFor[i]:lower()) then
                        v.Visible = true
                        print("yes")
                    else
                        v.Visible = false
                        print("no")
                    end
                end
            end
        end
    end
end)

Answer this question