Help with finding terminated/player's name with his user ID

  1. What do you want to achieve?
    Find the Username of a terminated/banned player with his user ID

  2. What is the issue?
    Roblox told me to remove him from all records, but i cant get to deleting his datastores because they’re using his username, i have tried this script but the server doesnt have permissions for such info.

local HttpService = game:GetService("HttpService")
local DataStoreService = game:GetService("DataStoreService")

local userId = 2798663781 -- The User ID of the terminated player

local function getUsernameFromUserId(userId)
	local url = "https://users.roblox.com/v1/users/" .. userId

	local success, response = pcall(function()
		return HttpService:GetAsync(url)
	end)

	if success then
		local userData = HttpService:JSONDecode(response)
		if userData and userData.name then
			return userData.name
		else
			warn("User data not found or account terminated for User ID: " .. userId)
			return nil
		end
	else
		warn("HTTP request failed for User ID: " .. userId .. " with error: " .. response)
		return nil
	end
end

local function removeUserData(username)
	local datastore = DataStoreService:GetDataStore(username .. "Stats")

	local success, err = pcall(function()
		-- You need to list all possible stats keys here
		local keys = {"Blorbs", "Level"} -- Replace with actual stat keys
		for _, key in ipairs(keys) do
			datastore:RemoveAsync(key)
		end
	end)

	if success then
		print("Successfully removed data for user:", username)
	else
		warn("Failed to remove data for user:", username, "Error:", err)
	end
end

local username = getUsernameFromUserId(userId)
if username then
	print("Username for User ID " .. userId .. " is " .. username)
	removeUserData(username)
else
	print("Username not found for User ID " .. userId)
end
  1. What solutions have you tried so far?
    I’ve looked in some posts and they told me to use some functions, then i built a script around it.
local Players = game:GetService("Players")

local userId = 2798663781

local function getUsernameFromUserId(userId)
	local success, username = pcall(function()
		return Players:GetNameFromUserIdAsync(userId)
	end)

	if success then
		return username
	else
		warn("Failed to get username: " .. username)
		return nil
	end
end

local username = getUsernameFromUserId(userId)
if username then
	print("Username: " .. username)
else
	print("Failed to retrieve username.")
end

And i ended up getting

Failed to get username: Players:GetUserIdFromNameAsync() failed: Unknown user 

I also tried using those terminated accounts link thing and they didnt work at all.

only thing i was able to pull from the userid was

“userName”: “[Account Deleted (2795387284)]”,
“displayName”: “Esteban”

1 Like

Thank you, i can work with that.

1 Like

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