Decided to submit this post using the required questions just so I don’t forget anything.
What are you attempting to achieve? (Keep it simple and clear)
The problem I am facing: I recently created a system which would input the player’s ID into a textbox and from there: it would show the player’s profile picture on an imagelabel together with their username
What is the issue? (Keep it simple and clear - Include screenshots/videos/GIFs if possible)
The issue: Right now the line giving me the most issues is this particular one:
game.Workspace.Display.BillboardGui.ImageLabel.Image = game:GetService("Players"):GetUserThumbnailAsync(tonumber(DatabaseBox.Text)),Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size150x150)
print(tonumber(DatabaseBox.Text))
game.Workspace.Display.BillboardGui.TextLabel.Text = player.Name
else
print(tonumber(DatabaseBox.Text))
end
Quick rundown just incase:
If the database input (numerized due to input compatibility) is NOT nil and not an empty string (basically two checks to make sure no empty input is provided) then:
the ImageLabel image would fetch the user, using their player ID which is a series of numbers, however:
(Not really a step but I figured it would help either way). With this particular parameter I figured: if the first parameter is a number, then numerizing string input like this should do the trick as well. However it did not and that’s why I am here
What solutions have you tried so far? (Have you searched for solutions through the Roblox Wiki yet?)
So far I tried using different functions, like GetPlayerFromUserId combined with this particular function (honestly just experimenting). I always consult the wiki before asking but since most are just plain variables and not really tutorials, I figured this was the place to ask
I hope this answers the question, if not feel free to ask for more details if I missed any.
For everyone asking where the “if” statement went: I likely forgot to include that, how I managed is what I would like to know from myself, too.
if tonumber(DatabaseBox.Text) ~= nil and DatabaseBox.Text ~= "" then
game.Workspace.Display.BillboardGui.ImageLabel.Image = game:GetService("Players"):GetUserThumbnailAsync(player..(tonumber(DatabaseBox.Text)),Enum.ThumbnailType.HeadShot,Enum.ThumbnailSize.Size150x150)
print(tonumber(DatabaseBox.Text))
game.Workspace.Display.BillboardGui.TextLabel.Text = player.Name
else
print(tonumber(DatabaseBox.Text))
end
Right, this should be more clear. Apologies about that.
The problem, in hindsight is it simply prints nil, aka there is no input despite my two checks being performed. I am unsure as to how or why this occurs.
the tonumber function returns nil if the string cannot be converted to a number, so I’d just print the TextBox’s text first just to check that the text is just numbers
I took out the tonumber function, and it still printed an empty string, which is weird because I performed various checks to prevent that. Apparently studio doesn’t think the same? So yeah. I don’t know what the issue could be right now.
Server, however the clickdetector script works with the player’s values (this script), the player… part has been reverted back to how it was which is player.id, I need it to be manually editable as stated.
Wait is the TextBox that you use for input in a ScreenGui? Because the server can’t access guis on the client. You’d have to use a remote event and fire the server with the TextBox’s text instead.
local Text_Remote = game:GetService('ReplicatedStorage')
local GUI = script.Parent
local TextBox = GUI.TextBox
function SendToServer()
if TextBox.Text ~= "" then
Text_Remote:FireServer(TextBox.Text)
end
end
SendToServer() -- Fire this function when you see fit e.g ButtonPress etc
Server
local Text_Remote = game:GetService('ReplicatedStorage')
local Players = game.Players
function RecieveText(player, text)
if typeof(text) == 'string' then -- checks if the client is actually sending text and not something we don't want
local PlayerSearch = Players:FindFirstChild(text)
if PlayerSearch then -- checks if the text matches a player
print(Player.Name, Player.UserID) -- prints the player's name and userid
end
end
end
Text_Remote.OnServerEvent:Connect(RecieveText)
hope this can help you
I didn’t check this in studio so if anything is wrong please correct me : )
It does work, atleast it lets me input. What I did was I set the SurfaceGui Adornee to the part itself, and parented it to the player therefor rendering it usable.
You should consider implementing a RemoteEvent/Function into this concept with Communication between the ServerScript and the LocalScript so it can access the Text. From there, it can return some type of value if needed. See @Quoteory’s post for more details.