1. What I want to achieve:
A UI with a Search Box in Runtime. Enter your search query. Output a list with found script objects.
Make the search results “Clickable”. When clicked, the player position changes to the parent location of the script object. In this example, the location of the flag.
Step #1:
Enter your Search Query
Step #2:
Click Search
Step #3:
Print the result list (output)
Step #4:
Make the Search Result Clickable
Step #5:
When “Clicked”, change your players location to the position of the scripts parent location. In this example, the position of the flag.
-
What is the issue?
I am stuck at Step #4 with the coding. I can’t make the search result clickable. And once clicked, I can’t change the player position to the script’s parent location. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I already looked for solutions in the Developer hub, but couldn’t find any answer.
I was able to create a script that outputs the search result. However, I can’t:
- I can’t make the search result clickable.
- I can’t change the players location when clicking the search result.
local UpdateScore = game:GetService("ReplicatedStorage").RemoteEvent
local workSpace = game:GetService("Workspace")
local players = game:GetService("Players")
local resultTextBox = script.Parent.resultText
resultTextBox.ClearTextOnFocus = false
local queryTextBox = script.Parent.queryText
local num = 0
local textButton = script.Parent.Search
-- Function to clean up the name and make it valid for button naming
local function CleanButtonName(name)
-- Replace any invalid characters with an underscore
return name:gsub("[^%w_]", "_")
end
textButton.MouseButton1Click:Connect(function()
local query = queryTextBox.Text
resultTextBox.Text = query
local allElements = workSpace:GetDescendants()
local scriptObjects = ""
local query = queryTextBox.Text:lower() -- Convert query to lowercase
for _, v in pairs(allElements) do
-- Check if the element is a descendant of the Script class
if v:IsA("Script") and query ~= "" then
-- Convert the element's name to lowercase for case-insensitive comparison
if string.find(v.Name:lower(), query) ~= nil then
local fullPath = v:GetFullName()
scriptObjects = scriptObjects .. v.Name .. " Location: " .. fullPath .. "\n"
end
end
end
-- Clear existing results
resultTextBox.Text = ""
-- Create clickable TextButton GUI elements for each result
local lineNum = 0
for name, fullPath in scriptObjects:gmatch("([^\n]*)\n") do
lineNum = lineNum + 1
local textButton = Instance.new("TextButton")
textButton.Name = CleanButtonName(name) -- Set the name of the button after cleaning it
textButton.Parent = resultTextBox
textButton.BackgroundColor3 = Color3.new(1, 1, 1)
textButton.BorderSizePixel = 0
textButton.Size = UDim2.new(1, 0, 0, 20)
textButton.Text = name .. " Location: " .. fullPath
textButton.TextColor3 = Color3.new(0, 0, 0)
textButton.TextSize = 14
-- Add a click event to each result button
textButton.MouseButton1Click:Connect(function()
-- Do something when the result is clicked
print("Clicked on: " .. fullPath)
end)
end
end)
Thanks for any little help, appreciate it!
Download: .rbxl place file
My_Search.rbxl (958.6 KB)