Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Создаем GUI элементы
- local ScreenGui = Instance.new("ScreenGui")
- local TextBox = Instance.new("TextBox")
- local ScrollingFrame = Instance.new("ScrollingFrame")
- -- Настраиваем свойства GUI элементов
- ScreenGui.Parent = game.Players.LocalPlayer:WaitForChild("PlayerGui")
- TextBox.Parent = ScreenGui
- TextBox.Size = UDim2.new(0, 200, 0, 50)
- TextBox.Position = UDim2.new(0.5, -100, 0.5, -25)
- TextBox.PlaceholderText = "Введите текст..."
- ScrollingFrame.Parent = ScreenGui
- ScrollingFrame.Size = UDim2.new(0, 200, 0, 200)
- ScrollingFrame.Position = UDim2.new(0.5, -100, 0.5, 35)
- ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, 0)
- ScrollingFrame.ScrollBarThickness = 10
- ScrollingFrame.Visible = false
- -- Значения для поиска
- local searchHistory = {"apple", "apricot", "banana", "blueberry", "grape", "orange", "watermelon"}
- -- Функция для обновления предложений
- local function updateSuggestions()
- local inputText = TextBox.Text:lower()
- ScrollingFrame:ClearAllChildren()
- ScrollingFrame.Visible = false
- if #inputText > 0 then
- local yOffset = 0
- for _, word in ipairs(searchHistory) do
- if word:sub(1, #inputText) == inputText then
- local SuggestionButton = Instance.new("TextButton")
- SuggestionButton.Parent = ScrollingFrame
- SuggestionButton.Size = UDim2.new(1, 0, 0, 50)
- SuggestionButton.Position = UDim2.new(0, 0, 0, yOffset)
- SuggestionButton.Text = word
- SuggestionButton.MouseButton1Click:Connect(function()
- TextBox.Text = word
- ScrollingFrame.Visible = false
- end)
- yOffset = yOffset + 50
- ScrollingFrame.CanvasSize = UDim2.new(0, 0, 0, yOffset)
- ScrollingFrame.Visible = true
- end
- end
- end
- end
- -- Обработчик ввода текста
- TextBox:GetPropertyChangedSignal("Text"):Connect(updateSuggestions)
- -- Обработчик нажатия Enter
- TextBox.FocusLost:Connect(function(enterPressed)
- if enterPressed then
- local newText = TextBox.Text
- local exists = false
- for _, word in ipairs(searchHistory) do
- if word:lower() == newText:lower() then
- exists = true
- break
- end
- end
- if not exists then
- table.insert(searchHistory, newText)
- end
- TextBox.Text = ""
- updateSuggestions()
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement