Search bar optimisation

Hey!

I have recently made this search bar but it’s a bit laggy and I was wondering how I could optimise it.

Script:

script.Parent:WaitForChild("Inventory").Search:GetPropertyChangedSignal("Text"):Connect(function()
	
	local val = script.Parent:WaitForChild("Inventory").Search.Text
	
	for i,v in pairs(script.Parent.Parent:WaitForChild("Storage"):GetChildren()) do
		v.Parent = script.Parent:WaitForChild("ScrollingFrame")
	end 
		
	if val ~= "Search" or val ~= "" or val ~= " " then
		
		print("1")
		
		for i,v in pairs(script.Parent:WaitForChild("ScrollingFrame"):GetChildren()) do

			if v:IsA("ImageButton") or v:IsA("TextButton") then

				if v:FindFirstChild("CardName") then
					
					print(val)
					print(v.CardName.Text)
					
					if v.CardName.Text ~= nil and val ~= nil and string.find(v.CardName.Text, val) then

						continue

					else
						
						v.Parent = script.Parent.Parent:WaitForChild("Storage")

					end

				end

			end

		end

	end
	
end)

Maybe try checking the value of search bar when the request is sent(for example: when button “Enter” is pressed, it will check the “Text” value)

Also add cooldown for the button