Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I wanna learn more about playeridasync?

Asked by 3 years ago

I was reading i think the devforum and was tryna find out what was playeridasync

I wanna know how to get a random player id from the current server you are in. I also wanna learn how does playeridasync works, thx alott

This is what I was talking about btw

https://developer.roblox.com/en-us/api-reference/function/Players/GetUserIdFromNameAsync

2 answers

Log in to vote
0
Answered by
Benbebop 1049 Moderation Voter
3 years ago

GetUserIdFromNameAsync seems to be more for getting a UserId from players who are offline or not in the server. For your situation it isnt needed.

Each player instance includes a UserId attribute, so simply get the children of Players and select a random item from that array.

local Players = game.Players:GetChildren()

local RandomUserId = Players[math.random(1, #Players)].UserId

Just for clarification, # gets the number of items in a table and [] gets the place in a table correspondent to the number contained in it.

0
That's exactly my answer.. SteamG00B 1633 — 3y
Ad
Log in to vote
0
Answered by
SteamG00B 1633 Moderation Voter
3 years ago
Edited 3 years ago

You don't need to use this to get an id of a player in the current server, just get a random number from 1 to the amount of players in the server, and then get a list of players and reference the UserId of the specified player in that list.

If you still wanted to use this, I don't know what you've done and why it's not working because the wiki link you provided even includes a code sample.

Answer this question