Script not waiting for functions response

This solution doesn’t work.

When I do this the script halts execution from that point, and doesn’t do anything beyond it (including other parts of the list.)

Could a solution be doing something like:

local chosenValue

...

newEntry.Button.MouseButton1Click:Connect(function()
	chosenValue = entry[3]
				
	listFrame.Visible = false
end)

...

repeat
	task.wait(0.1)
until chosenValue ~= nil
	
return chosenValue

be better?