Search system does not work?

Hello,

I have tried to make a search system where the users search for an item. This works, but only goes to one TextLabel (“Numbah3”). Here’s the Local Script:

local textBox = script.Parent

textBox.FocusLost:Connect(function(enter)
	if enter then
		for _,v in pairs(textBox.Parent:GetChildren()) do
			if v:IsA("TextLabel") then
				local text = v.Text
				local substringed = string.sub(v.Text,1,#textBox.Text)
				local function search()
					while wait() do
						if substringed == string.sub(v.Text,1,#textBox.Text) then
							for _,t in pairs(textBox.Parent:GetChildren()) do
								if t:IsA("TextLabel") then
									t.Transparency = 1
								end
							end
							v.Transparency = 0
						end
					end
				end
				search()
			end
		end
	end
end)

I don’t really know how to script these types of stuff well so help is appreciated.

while wait() do

You have an unyielding loop in your code, which means it gets stuck doing the same thing. If you completely remove the while wait() do thing, does it work correctly?

replace this code with this:

if substringed == textBox.Text then
  v.Transparency = 0
else
  v.Transparency = 1
end

It doesn’t work correctly, it goes to another TextLabel.

I literally thought of that solution…

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.