[lock me] There is a way to get a users rank from their userid?

Is there a way to get their id and use that to get their rank in a group?

1 Like
local GroupId = 0
game.Players.PlayerAdded:Connect(function(player)
	local PlayerRank = player:GetRankInGroup(GroupId)
end)
1 Like

There is this handy function :slight_smile:
YourPlayer:GetRankInGroup(YourGroupsID)

You can use GetRankInGroup alongside pcalls to get the player’s rank

pcalls are very essential here.

We understand that but we are trying to get their rank in a group without their player object.

1 Like
local groupID = 000000


game.Players.PlayerAdded:Connect(function(Player)
	local Success, Result = pcall(function()
		return Player:GetRankInGroup(groupID)
	end)

	if Success then
		print(Result) -- prints his rank
	end
end)```
local GroupId = 0

local UserId = 0
local player = game.Players:GetPlayerByUserId(UserId)
	
	local Success, Result = pcall(function()
		return player:GetRankInGroup(GroupId)
	end)

	if Success then
		print(Result) -- prints his rank
	end

For that, use GetGroupsAsync()

WITHOUT THE PLAYERS OBJECT, LISTEN THE FIRST TIME. we do not have the player object just their id.

1 Like

We know how to get someone’s rank, what we don’t know is how to get someone’s rank if they aren’t in the game.

game.Players isn’t only checking for players in-game, but for all players on roblox.
You can use it to get any player’s ID.

no no it doesnt. my old friend…

image

print(game.Players:GetNameFromUserIdAsync(1)) -- Roblox

print(game.Players:GetUserIdFromNameAsync("Roblox")) -- 1

You probably did something like this -

print(game.Players.Valkyrop)

This return group that player joined.

local UserId = 0
local player = game.Players:GetPlayerByUserId(UserId)
	
game.Players.PlayerAdded:Connect(function(player)
	local JoinedGroups = game:GetService("GroupService"):GetGroupsAsync(UserId)
	print(JoinedGroups)
end)

This work.

local GroupId = 0000000

local UserId = 0000000
	
local JoinedGroups = game:GetService("GroupService"):GetGroupsAsync(UserId)
	for _, v in pairs(JoinedGroups) do
		if v["Id"] == GroupId then
			print(v["Role"])
		end
	end

--Services
local Players = game:GetService("Players")
local Group = game:GetService("GroupService")

--Variables
local groupID = 000000
local PlayerID = 00000 -- put here your player's ID


Players.PlayerAdded:Connect(function(Player)
    --We use a pcall because GetGroupAsync is a Roblox web signal, and when the web is down, that function will not run properly in your script.
	local Success, Result = pcall(function()
		return Group:GetGroupsAsync(PlayerID)
	end)

	if Success then
		for _, value in pairs(Result) do
			if value["Id"] == groupID then
				print(value["Role"]) -- prints the Role of the player
                print(value["Rank"]) -- prints the Rank of the player
			end
		end
	end
end)
1 Like

But we want to know that is you will get error from Roblox studio maybe you need to fix that