How would i get the players userid from their name?

Ok so, Im making a add admin thing, and i need help with getting the players UserId when their name is written in the textbox. (screenshot below)

Is the player in the name? If so then just use

Local textbox = — define here
Local userid = game.Player:FindFirstChild(textbox.Text).UserId

1 Like

If the player is in same server, you can get their UserId with PlayerInstance.UserId.

If the player is not in the same server you can use GetUserIdFromNameAsync, game:GetService("Players"):GetUserIdFromNameAsync(playerName)

6 Likes

I tried combining both yours and @MayorGnarwhal’s suggestions and this is what i did.

local player = addpanel.Player
local userid = game:GetService("Players"):GetUserIdFromNameAsync(player.Text)

console:

Are you sure you spelled it right??

1 Like

Yes, I spelled everything correctly.

this is the entire script incase you need it:

local admins = {216571167, }
local addpanel = script.Parent.addpanel
local addbutton = addpanel.Add
local player = addpanel.Player
local userid = game:GetService("Players"):GetUserIdFromNameAsync(player.Text)

game:GetService("Players").PlayerAdded:Connect(function(plr)
	if table.find(admins, plr.UserId)then
		local clone = script.adminpanel:Clone()
		clone.Parent = plr:WaitForChild("PlayerGui", 5)
	end
end)

function addAdmin(plr)
	if not table.find(admins, plr)then
		table.insert(admins, plr)
		local clone = script.adminpanel:Clone()
		clone.Parent = plr:WaitForChild("PlayerGui", 5)
		return "Successfully made"..plr.."an admin!"
	else
		return "Player is already an admin!"
	end
end

addbutton.MouseButton1Click:Connect(function()
	addAdmin(userid)
end)

Well the problem is that that line will fire right away, before you have a chance to write their name in the textbox. Therefore you will be trying to get the UserId of the name “”

that would not make sense, if he puts it inside of where it activates

You have to write the players name in the textbox first, and then click the button.

What do you mean? He has it on line 5.

I meant that if he just puts it on where it activates it would work but still add some checking if the textbox is nil or not

Yeah eactly. Just move it inside the addAdmin function.

You’re defining the player’s userid before you input any text.

local userid = game:GetService(“Players”):GetUserIdFromNameAsync(player.Text)

Move the above line of code into your function.

1 Like

Let me understand. You are setting a table of Admis in a Local Script in your client. I suppose you will be the only one who can use it. But, once you store a player into ur client table, that will be useless.
You should code that table into a Server Script stored into ServerScriptService.

Use a remote from ur Local Script. Tell the server to store the Admin, and use that Server table as the core.
And yeah, make the GetUserIdFromNameAsync on the event got from the Click Gui Button

1 Like

Ok so I changed the script, can you tell me how I would store the player in the list?

local admins = {216571167, }
local addpanel = script.Parent.addpanel
local addbutton = addpanel.Add
local player = addpanel.Player


game:GetService("Players").PlayerAdded:Connect(function(plr)
	if table.find(admins, plr.UserId)then
		local clone = script.adminpanel:Clone()
		clone.Parent = plr:WaitForChild("PlayerGui", 5)
	end
end)

function addAdmin(plr)
	if not table.find(admins, plr)then
		table.insert(admins, plr)
		local clone = script.adminpanel:Clone()
		clone.Parent = plr:WaitForChild("PlayerGui", 5)
		return "Successfully made"..plr.."an admin!"
	else
		return "Player is already an admin!"
	end
end

addbutton.MouseButton1Click:Connect(function()
	local userid = game:GetService("Players"):GetUserIdFromNameAsync(player.Text)
	addAdmin(userid)
end)

You are already saving the player id into admins = {}

I meant that you are saving it on client, locally. No one using that admin panel will see ur local table. I just suggest make a remote to manage that array into a ServerScript

1 Like

Could you walk me through on how to do that? im a noob ;-;

1 Like

Just add some context first. What is that panel supposed to do?
You are the only one who uses it? Any admin can use it? What will the panel will do? It will have options to do stuff? Its for adding players as admins and thats all?

If u want to preserve that admins list tru games, then u will need use a datastore too.
Just asnwer that, and I can help you c:

1 Like

Im making an admin panel for all admins to use in a small game im making. the panel will do basic admin stuff, like kick, warn, ban, and maybe commands to do with the game, and editing leaderstats.