Fetch Player's ID through use of TextBox?

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

@Quoteory
image
Getting there but I see it still prints when there is only placeholder text, while it specifies actual text, is this a mistake or does the gui/script see text and placeholdertext as the same thing?

Try this?

local TextBox = script.Parent -- Identify the TextBox
TextBox.Text = ""
local remote = game:GetService("ReplicatedStorage").RemoteEvent

function SendToServer()
	
	if TextBox.Text ~= "" and TextBox.Text:upper() == TextBox.Text  then
		
		print("works")
		
		remote:FireServer(tostring(TextBox.Text))
		
	end
	
end
-- Add a event that can be run to send the info to the server
TextBox:GetPropertyChangedSignal("Text"):Connect(SendToServer)

I hooked the Property Changed Signal to make sure it only receives input from the Text as an Example.

2 Likes

Wow. Like, four people asked the same question at the start.

Heya. Sounds like you’ve got an XY Problem on your hands, or something similar to it. Your issue isn’t fetching the Player’s UserId from a TextBox, it’s the application of your code here.

Keep in mind that more than one value is returned from GetUserThumbnailAsync. You should attempt to make use of these arguments, because that may be part of your problem (you can use these to debug).

As a side note, for good practice, you should wrap this in a pcall. GetUserThumbnailAsync is a web call internally, therefore if it fails it can also terminate your thread. Here’s a little test you can try.

local Players = game:GetService("Players")

local success, content, ready = pcall(Players.GetUserThumbnailAsync, Players, UserId, ThumbnailType, ThumbnailSize)
if success then
    if ready then
        ImageLabel.Image = content
    else
        -- Handle image not ready
    end
else
    -- Handle call failure
end

I do believe that the string of content remains empty if the image is not ready to be used, though I could be wrong. I haven’t really touched this function.

Do lots of debugging. Try throwing print statements around in your code to see where exactly your implementation isn’t working out and to see what gets returned from some calls.

I can’t really grasp the issue because there are obscure respond-and-grab messages here. What’s primarily your issue? Is everything working except the display of images, or is your code having errors as well? Checking the console would also help out.

1 Like