-
Click the Result in Output Box → Change Player Location to the object clicked in the search result
-
Player location doesn’t change after I click the search result
-
I tried to find the problem in my script. But no luck.
After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!
-- This is an example Lua code block
local ScrollingBoxScreenGui = script.Parent
local ScrollingFrame = ScrollingBoxScreenGui.Frame.ScrollingFrame
local searchEvent = game.ReplicatedStorage.SearchEvent -- Change 'SearchEvent' to your RemoteEvent name
-- Function to add items to the scrolling frame
local function AddItem(text)
local item = Instance.new("TextButton") -- Use TextButton instead of TextLabel for clickable items
item.Parent = ScrollingFrame
item.Size = UDim2.new(1, 0, 0, 30) -- You can adjust the size as needed
item.Position = UDim2.new(0, 0, 0, #ScrollingFrame:GetChildren() * 30) -- Vertically position the item
item.BackgroundColor3 = Color3.fromRGB(255, 255, 255)
item.Text = text
item.TextSize = 20
-- Add a click event handler
item.MouseButton1Click:Connect(function()
-- Teleport the player to the selected location
local targetPosition = Vector3.new(0, 10, 0) -- Replace this with the actual position of the selected location
game.Players.LocalPlayer.Character:SetPrimaryPartCFrame(CFrame.new(targetPosition))
end)
end
-- Listen for the search event from the server
searchEvent.OnClientEvent:Connect(function(results)
-- Clear existing items in the scrolling frame
for _, item in ipairs(ScrollingFrame:GetChildren()) do
item:Destroy()
end
-- Add search results to the scrolling frame
for _, result in ipairs(results) do
AddItem(result)
end
end)
Not sure what could be wrong with the click even handler.
Anyone any ideas?
Appreciate any little help.
You can download the .rbxl place file right here:
Click Event Location.rbxl (59.6 KB)