im working on a plugin where you can load characters of players, im working on the textbox rn, but i encountered an error; i type theplayer’s name but it doesn’t even do anything nor show pfp
1. local box = script.Parent
2. local img = box.Parent:WaitForChild("PlayerImage")
3. local players = game:GetService("Players")
4. box.FocusLost:Connect(function(enterpressed, loser)
5. if enterpressed then
6. local player = players:FindFirstChild(box.Text)
7. if player then
8. img.Image = players:GetUserThumbnailAsync(player.UserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
9. end
10. end)
There are no players underneath Players in studio, unless you’re in team create. And even then, you could only load the images of team create members
local box = script.Parent
local img = box.Parent:WaitForChild("PlayerImage")
local players = game:GetService("Players")
box.FocusLost:Connect(function(enterpressed, loser)
if enterpressed then
local success, userId = pcall(players.GetUserIdFromNameAsync, players, box.Text) -- fetch the player's UserId from the given name
if success then -- check that the pcall was successful
img.Image = players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
else
warn(userId) -- warn the error message if something when wrong
end
end
end)
game:GetService("Players"):GetUserIdFromNameAsync(playerName)
This is what you’re looking for, I made the changes for you already. You just input the user’s name
local box = script.Parent
local img = box.Parent:WaitForChild("PlayerImage")
local players = game:GetService("Players")
box.FocusLost:Connect(function(enterpressed, loser)
if enterpressed then
local userid = game:GetService("Players"):GetUserIdFromNameAsync(box.Text)
if userid then
img.Image = players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
end
end
end)
local box = script.Parent
local img = box.Parent:WaitForChild("PlayerImage")
local players = game:GetService("Players")
box.FocusLost:Connect(function(enterpressed, loser)
if enterpressed then
local isUserId = tonumber(box.Text)
if not isUserId then
local userid = game:GetService("Players"):GetUserIdFromNameAsync(box.Text)
if userid then
img.Image = players:GetUserThumbnailAsync(userid, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
end
else
img.Image = players:GetUserThumbnailAsync(isUserId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
end
end
end)
-- Example
local searchByUserId = false
ToggleButton.MouseButton1Click:Connect(function()
searchByUserId = not searchByUserId -- if the value is 'false', set it to true and vice versa
end)
box.FocusLost:Connect(function(enterpressed, loser)
if enterpressed then
local userId = 0
if not searchByUserId then -- search by username
local success, output = pcall(players.GetUserIdFromNameAsync, players, box.Text) -- fetch the player's UserId from the given name
if not success then -- check that the pcall was successful
warn(userId) -- warn the error message if something when wrong
return
else
userId = output -- set the userid to the output
end
else
userId = tonumber(box.Text) -- the user switched to search by user ids
end
img.Image = players:GetUserThumbnailAsync(userId, Enum.ThumbnailType.HeadShot, Enum.ThumbnailSize.Size420x420)
end
end)
Keep in mind that when the user switches the search functionality, you should give them a visual indicator of that (like: “Now searching by UserId”)