I have a list of usernames that I need to ban from my game, however the system only accepts their ID. So far it’s tedious to go through the list look up the player and copy their ID. Would there be a script that would be able to take the list of users and print out the ID? TIA!!
https://create.roblox.com/docs/reference/engine/classes/Players#GetUserIdFromNameAsync
Players:GetUserIdFromNameAsync(username) -- Returns the UserId from the provided Username
Is it in a table? If it is, you can use a loop to get all the ids.
local PlayersToBan = {} – Names of players –
for i,v : Player in pairs(PlayersToBan) do – Loops through the table –
print(game:GetService(“Players”):GetUserIdFromNameAsync(v)) --Gives the Id of player –
end
--!strict
local players: Players = game:GetService("Players")
--// Takes list of usernames as parameter, returns the IDs
local function UsernamesToIDs(usernames: string): string
-- Split by either ", " or " "
local usernamesArray: {string} = string.split(usernames, if string.find(usernames, ",") then ", " else " ")
local idsToReturn = ""
for i,username in pairs(usernamesArray) do
local id: number = players:GetUserIdFromNameAsync(username)
--// You can modify the ", " to your own separator
idsToReturn ..= id .. (if i == #usernamesArray then "" else ", ")
end
return idsToReturn
end
Example implementation:
print(UsernamesToIDs("roblox, builderman, GetWreckedDJ11"))
Output:
1, 156, 194839637