Fetch Player's ID through use of TextBox?

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:

  1. 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:
  2. the ImageLabel image would fetch the user, using their player ID which is a series of numbers, however:
  3. (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.

1 Like

What is going wrong with this? Is there an error, or is there just nothing happening? You never actually mentioned a problem, unless I am going blind.

Why do you have an else and no if statement?

Could you please explain in more detail on what issue is prominent in your code?

Can you elaborate on what the actual issue is and what intended behavior is. Felt pretty unclear to me atleast.

I am very confused as to what your issue is.

Also, some things I’d like to point out:

  1. Why do you have an else statement if there is no “if” statement?
  2. There is an “end” even though there is no function/statement.

Please elaborate more on your issue.

1 Like

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.

1 Like

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.

Just asking to clarify, this is a local script right?

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.

Could you show your current script, not exactly sure what you mean

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.

1 Like

This should help

client(local)

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 : )

and sorry if this is not what you’re looking for

Display = game.Workspace.Terminal.TerminalBase.SurfaceGui.TextBox
DatabaseBox = game.Workspace.testpart.SurfaceGui.TextBox
power = game.Workspace.Terminal.TerminalBase.SurfaceGui.PowerState
game.Workspace.Display.BillboardGui.Enabled = false

clickdetector.MouseClick:Connect(function(player)
	if power.Text == "Off" then
		Display.Text = "No power"
		wait(1)
		Display.Text = "Results display here"
		game.Workspace.Display.BillboardGui.Enabled = false
	elseif DatabaseBox.Text == DatabaseBox.PlaceholderText then
	Display.Text = "Input required."
	wait(1)
	Display.Text = "Results display here"
	
	
	elseif power.Text == "On" then
	game.Workspace.Display.BillboardGui.Enabled = true
	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(DatabaseBox.Text)
		end
	end
end)

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.

As long as the SurfaceGui is parented to the player’s gui the server can’t access its text

This is not the case, as you can still access them via RemoteEvents/Functions. But in the given context, yes, you are correct.

1 Like

I know, but he isn’t using remotes, so as it is now, it can’t access it

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.

1 Like