Is there any way i can select a random player from All the roblox Users? (Not from the In-game Players)
What exactly do you mean by select? do you want to pull them out of the game?
I would like a Select a random player from all the existing roblox players and Load their Avatar.
This would be hard to do because there are millions of players, but what you could do is generate random usernames and check if those names exist.
Yeah i thought about that, but when i generated random strings for my older projects (using letters and numbers)
Most of the time i got “a97sodnasd”
There is currently a plugin Called load character, and it allows you to load in any roblox character you please Load Character Pro - Roblox
Yep i know that plugin and i use it frequently the thing is
- it doesnt get a random player
Have you ever played the Roblox game Super place roulette?
Every time it gets a random Game and teleports players to it. its very interesting
- is it possible to do the same with players?
https://www.roblox.com/games/3582601336/Super-Place-Roulette
Here is just an idea, you could select a random player that is currently in the game. Then use Player :GetFriendsAsync to select a random friend, then select a random friend from that friend etc. After a few times it will select a player that is basically random.
So i could basically Get the friend, of a friend, of a friend? Hmm, yeah that is indeed pretty random. Maybe that is as close as it can get
You can try to generate a random ID that is ranged between 1 and 2 billion. Since there are a lot of banned accounts, you would have to generate it again until it’s a valid account.
edit: this should be useful in your case
I don’t think there is an API that lists every player in Roblox. You would have better luck selecting a random person from a friends list as mentioned above.
If you did that 20 times, and each person had 100 friends, then it would be a random person out of 100^20 people.
I’ve played that game a lot, the thing is i dont think there is an existing script that can make this happen
I think generating ID’s and :GetFriendsAsync seem like the best options for now.
I will try them all and keep the thread updated i guess.
Something simple with recursion should work fine
local Players = game:GetService("Players")
local GetNameFromUserIdAsync = Players.GetNameFromUserIdAsync
local function randomUser()
local randomId = math.random(1, 2000000000)
local success, res = pcall(GetNameFromUserIdAsync, Players, randomId)
if success then
return res
else
return randomUser()
end
end
print(randomUser())
Yes indeed! it works very well, thank you so much, that was very helpful.
Today, our lucky random generated used was
- Thanks to everyone who participated in this thread!
Edit: Nevermind, just realized that the Characters of Terminated users cannot actually be loaded, but I’ll keep this here for extra info.
I’m fairly sure that :GetNameFromUserIdAsync()
works in most cases, even if the user is terminated (with the exceptions for accounts that were closed due to GDPR requests along with some of the earliest accounts, such as those with UserIds of 4, 5, 7, etc.). For example:
local Players = game:GetService("Players")
local GetNameFromUserIdAsync = Players.GetNameFromUserIdAsync
local function randomUser(UserId)
local success, res = pcall(GetNameFromUserIdAsync, Players, UserId)
if success and res then
return res
else
return "Unable to retrieve username"
end
end
print(randomUser(4)) -- Unable to retrieve username (One of the earliest accounts)
print(randomUser(7936)) -- miked (Terminated)
print(randomUser(617197)) -- jaredvaldez4 (Terminated)
And if the OP wanted to avoid loading Characters of terminated users, from my understanding & based on previous research I’ve done, the most reliable way to determine if a user is terminated is by utilizing Roblox’s Users Api
(more specifically, the /v1/users/{userId} endpoint) and checking if the isBanned
bool returns true or not.
GetNameFromUserIdAsync is already sending an http request to the api, it would be faster to use functions that they provide. Plus, a proxy would be needed which would slow down the requests.
I was only referring to the usage of that specific endpoint for definitively determining whether or not a user is terminated, since the example I provided in my post demonstrated that the name of some terminated accounts can still be retrieved via the GetNameFromUserIdAsync
method.
I realized shortly after posting the message that for the use case of the OP, they could continue to use GetNameFromUserIdAsync
as you suggested, since they could simply check if loading the Character errors or not.