Frame won't go invisible

I am experiencing a strange issue where when the TextBox is being changed (The Text) two Frames visibility should change. One of them being the default one and the other one the new frame. However the Frames won’t go invisible at all.

script.Parent.SearchBox:GetPropertyChangedSignal("Text"):Connect(function()
	print("test")
	script.Parent.SearchFrame.Visible = true
	script.Parent.ScrollingFrame.Visible = false

I am not sure what I am doing wrong since I’ve looked on the Forum but no one has been having this same issue that I could find.

3 Likes

try this

script.Parent.SearchBox:GetPropertyChangedSignal("Text"):Connect(function()
    local searchText = script.Parent.SearchBox.Text
    
    if searchText ~= "" then
        script.Parent.SearchFrame.Visible = true
        script.Parent.ScrollingFrame.Visible = false
    else
        script.Parent.SearchFrame.Visible = false
        script.Parent.ScrollingFrame.Visible = true
    end
end)

make sure you’ve placed this code in the right place within your script and that the references to the frames (SearchFrame and ScrollingFrame ) are correct.

4 Likes

This still gives the same issue

2 Likes

They are in the correct place in the StarterGui and the Script is.
image

2 Likes

I just removed the majority of my code in the LocalScript and it worked when I removed my code it was just

script.Parent.SearchBox:GetPropertyChangedSignal("Text"):Connect(function()
	script.Parent.ScrollingFrame.Visible = false
	script.Parent.SearchFrame.Visible = true
end)

This worked but when I have my entire code:

local players = {} -- Create a table

script.Parent.SearchBox:GetPropertyChangedSignal("Text"):Connect(function() -- start when the text is changed
	script.Parent.ScrollingFrame.Visible = false
	script.Parent.SearchFrame.Visible = true
	for _, player in ipairs(game:GetService('ReplicatedStorage').Vehicles.Sedans:GetChildren()) do -- get a list of all players
		players[player.Name] = player.Name -- absolutely no clue
	end

	for _, name in pairs(players) do
		if (script.Parent.SearchBox.Text:lower():sub(1, 4) == name:sub(1, 4)) then -- if the text upto 4 characters matches then
			for _, v in pairs(script.Parent.SearchFrame:GetChildren()) do
				if script.Parent.SearchFrame:FindFirstChild(name) then
				else
					local clone = script.Parent.CloneThisSearch:Clone()
					clone.Parent = script.Parent.SearchFrame
					clone.Name = name
					clone.VehicleName.Text = name
					clone.Visible = true
					
				end
			end
		else
			for _, v in pairs(script.Parent.SearchFrame:GetChildren()) do
				if v:IsA("Frame") and v.Name ~= "CloneThisSearch" then
					v:Destroy()
				end
			end
			script.Parent.SearchFrame.Visible = false
			script.Parent.ScrollingFrame.Visible = true
		end
	end
end)

It does not work?

2 Likes

Your frames are being created and destroyed in quick succession. Which causes the frames to not be correctly updated in terms of visibility and their names.

can you try this code

local function updateSearchResults(searchText)
    local nameMatches = {}

    for _, player in ipairs(game:GetService('ReplicatedStorage').Vehicles.Sedans:GetChildren()) do
        local playerName = player.Name
        if searchText:lower():sub(1, 4) == playerName:sub(1, 4) then
            table.insert(nameMatches, playerName)
        end
    end

    script.Parent.ScrollingFrame.Visible = #nameMatches == 0
    script.Parent.SearchFrame.Visible = #nameMatches > 0

    -- Clear existing search results
    for _, v in pairs(script.Parent.SearchFrame:GetChildren()) do
        if v:IsA("Frame") and v.Name ~= "CloneThisSearch" then
            v:Destroy()
        end
    end

    -- Create new search result frames
    for _, name in ipairs(nameMatches) do
        local existingFrame = script.Parent.SearchFrame:FindFirstChild(name)
        if not existingFrame then
            local clone = script.Parent.CloneThisSearch:Clone()
            clone.Parent = script.Parent.SearchFrame
            clone.Name = name
            clone.VehicleName.Text = name
            clone.Visible = true
        end
    end
end

script.Parent.SearchBox:GetPropertyChangedSignal("Text"):Connect(function()
    local searchText = script.Parent.SearchBox.Text
    updateSearchResults(searchText)
end)

Also remember to adjust the code as needed to match the exact hierarchy and names of your gui elements.

3 Likes

This worked perfectly, thank you for fixing this for me. Greatly appreciated!

1 Like

anytime! don’t forget to mark my answer as the solution :stuck_out_tongue_closed_eyes:

2 Likes

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