You can write your topic however you want, but you need to answer these questions:
-
What do you want to achieve? Keep it simple and clear!
I want to achieve getting my GUI to work when you search the player name in well show the box in the player profile picture -
What is the issue? Include screenshots / videos if possible!
on my GUI when I try to search the player name when i look at the logs it says player not found when I enter the name right -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I try everything
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!
here my GUI script
--local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
-- References to GUI elements
local searchBox = script.Parent.Roundify.Gradient.TextBox
local profileDisplay = searchBox.Parent:WaitForChild("Frame")
local profilePicture = profileDisplay:WaitForChild("ImageLabel")
local playerNameLabel = profileDisplay:WaitForChild("TextLabel")
local SearchPlayerEvent = ReplicatedStorage:WaitForChild("SearchPlayerEvent")
local localPlayer = Players.LocalPlayer
-- Function to fetch player headshot URL
local function getPlayerHeadshot(playerId)
return string.format("https://www.roblox.com/headshot-thumbnail/image?userId=%d&width=420&height=420&format=png", playerId)
end
-- Function to search and display player profile
local function searchAndDisplay(playerName)
if playerName == "" then
profileDisplay.Visible = false
return
end
-- Call the server to search for the player
SearchPlayerEvent:FireServer(playerName)
end
-- Listen for the server's response
SearchPlayerEvent.OnClientEvent:Connect(function(playerInfo)
if playerInfo then
local userId = playerInfo.id
local displayName = playerInfo.displayName
-- Update Profile Display
profilePicture.Image = getPlayerHeadshot(userId)
playerNameLabel.Text = displayName
profileDisplay.Visible = true
else
-- Handle player not found
profileDisplay.Visible = false
warn("Player not found!")
end
end)
-- Automatically search as the user types
searchBox:GetPropertyChangedSignal("Text"):Connect(function()
searchAndDisplay(searchBox.Text)
end)
here is my module script
local HttpService = game:GetService("HttpService")
local PlayerSearchModule = {}
function PlayerSearchModule:SearchPlayer(playerName)
local success, playerData = pcall(function()
return HttpService:JSONDecode(HttpService:GetAsync("https://users.roblox.com/v1/users/search?keyword=" .. playerName .. "&limit=1"))
end)
if success and playerData and playerData.data and playerData.data[1] then
return playerData.data[1]
else
return nil
end
end
return PlayerSearchModule
here my server script
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local PlayerSearchModule = require(script.Parent.PlayerSearchModule)
local SearchPlayerEvent = ReplicatedStorage:WaitForChild("SearchPlayerEvent")
SearchPlayerEvent.OnServerEvent:Connect(function(player, playerName)
local playerInfo = PlayerSearchModule:SearchPlayer(playerName)
SearchPlayerEvent:FireClient(player, playerInfo)
end)