Get User ID From Text

I’m making a Mod/Admin Panel for my game, and I’m trying to make the script get the User ID of the player in the Username TextBox, This is the error I get.

Error:

Script:

local UsernameText = script.Parent.Username.Input
local UserIdText = script.Parent.UserId.Input

local function GetUserId()
	local Success, UserIdResult = pcall(game.Players:GetUserIdFromNameAsync(UsernameText.Text), game.Players, UsernameText.Text)

	if Success then
		UserIdText.Text = tostring(UserIdResult)
	end
end

UsernameText.Changed:Connect(GetUserId)
local Success, UserIdResult = pcall(game.Players.GetUserIdFromNameAsync, UsernameText.Text)

You were calling the function to be ran inside the pcall instead of passing the function itself

local Success, UserIdResult = pcall(game.Players.GetUserIdFromNameAsync, game.Players, UsernameText.Text)

I got it

local UsernameText = script.Parent.Username.Input
local UserIdText = script.Parent.UserId.Input

local function GetUserId()
	local username = UsernameText.Text
	if username ~= "" then
		local success, userId
		local status, result = pcall(function()
			userId = game.Players:GetUserIdFromNameAsync(username)
		end)

		if status then
			UserIdText.Text = tostring(userId)
		else
			warn("Failed to get UserId:", result)
			UserIdText.Text = ""
		end
	else
		UserIdText.Text = ""
	end
end

UsernameText.FocusLost:Connect(GetUserId)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.