Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get a player's username, id from a textbox input and make sure it exists?

local GUI = script.Parent
local open = GUI.Open
local Target = GUI.AdminFrame.Main_Frame.Target
local UserImage = GUI.AdminFrame.Main_Frame.UserThumbnail
local UserPlayerId = GUI.AdminFrame.Main_Frame.UserPLRid
local Username = GUI.AdminFrame.Main_Frame.UserName
local check = GUI.AdminFrame.Main_Frame.Check
local status = GUI.AdminFrame.Main_Frame.Status

check.MouseButton1Click:Connect(function()
	if Target.Text == "" then
		status.Text = "Invalid username!"
		wait(1)
		status.Text = ""
	elseif Target.Text ~= "" then
		
	end
end)

This is a LocalScript for an admingui I have and basically when a player inputs a player username and clicks the check button, it checks if the textbox is blank. If so, set a text to inform the player that the inputted text is invalid. Else if it isn't a blank text then display the player's username, userid and their image thumbnail (Headshot). How do I make it check if a player with that username exists, and then get a player's username and userid from an inputted TextBox. If there isn't a way to do so, is there an alternative?

Important note: I want to fetch a player's username and userid from a string value WHILST that player is NOT ingame (if that's possible).

1 answer

✓ Accepted answer

There are 2 methods you can use on the Players service:

Fetch user id from name: https://developer.roblox.com/en-us/api-reference/function/Players/GetUserIdFromNameAsync

Fetch name from user id: https://developer.roblox.com/en-us/api-reference/function/Players/GetNameFromUserIdAsync

With these 2 methods you can search for both user ID and username in order to find both. (Little trick you can do, check if the textbox value has any non digit in the text, if so you can automatically determine the search as being a username. If not search for userId first and then username if the first one didn't give a result). Alternatively if you only need to search on the name you can just use option 1 and ignore option 2.

1 comment

0

Thank you, I've been looking for this!

This discussion is preserved as it was. New answers, comments, and votes are closed.