How would I index and display a search?

Hi!
Here I am with my over complex issues again.
But, this time I’m kind of stuck on making a Search for my build mode.
How would I do it?
It would search for categories or furniture depending on the attribute

function Building.IndexSearch(Player,SearchContext,Indexed) --SearchConext is explained in the next few lines, this should index the search.
	print("Indexing Search Content: "..SearchContext)
       if Player.PlayerGui:WaitForChild("?Build"):GetAttribute("MenuOpen") == "Items" then
             print("SearchType Items")
     else
             print("SearchType Categories")
	Indexed = false
	-------
	print("Indexed!")
	Indexed = true
	
	
end

function Building.DisplaySearch(Player,SearchContext,Indexed)
	if Building.IndexSearch(nil,nil,true) then --Pretty sure this wouldn't work
		print("Displaying search..")
	else
		
	end
end

Thanks for any help!

Does anybody have an answer? Nothing yet…

Go through each item / category and use string.sub() to check if an item / category has the string in it.

Edit: string.find() is the one you looking for.

1 Like

are you everywhere on the forums?
Can I see an example in the code I would use? My co scripter is asleep I think lol
Because this is in a Module in RepStorage
guessing it’s just me
image

1 Like

I’m following you so I get notifications.

Okay, long behold my fruit table example:

local fruit = {"apple", "pineapple", "banana", "kiwi"}
-- In our example, when we search 'apple' we likely want 'apple' and 'pineapple' to be returned as they contain 'apple'
local search = string.lower("apple") -- Replace "apple" with your search term.
local Return = {}
for _, currentFruit in ipairs(fruit) do
local Lowercase = string.lower(currentFruit) -- Get rid of the pesky upper case letters
local Find = string.find(Lowercase, search) -- Find it
if Find then
table.insert(Return, currentFruit)
end
end
print(Return)

It prints an array with ‘the search term’

Edit: @pyxfluff I updated the code to not require the search term to be lowercase.

2 Likes

Ok, let me test now.

1 Like

It doesn’t work, In my case at least.


(I will be editing it later to work with the module, etc

1 Like

You must use the code in the module as it prints it out.

Also, .Text is likely to be “” when you start.

2 Likes

I will try to add it, hold on…

Dont know how to make it work with all the functions and stuff, and it’s still kinda early for my co scripter, so idk what’s going on there.
Gonna way for a response.

1 Like