-
What do you want to achieve?
Find the Username of a terminated/banned player with his user ID -
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
-
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.