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

Rank GUI not displaying ranks?

Asked by 6 years ago
Edited 6 years ago
game.Players.PlayerAdded:connect(function(player)

local leaderstats = Instance.new("IntValue") leaderstats.Name = "leaderstats" leaderstats.Value = 0

local rank = Instance.new("StringValue") rank.Name = "Rank"
rank.Parent = leaderstats

rank.Value = player:GetRoleInGroup(3975371) -- put group id in parentheses

leaderstats.Parent = player 

end)

I've double checked the group ID and that is all fine, is there any reason this does not work?

0
Please use a code block tictac67 96 — 6y

2 answers

Log in to vote
1
Answered by 6 years ago
Edited 6 years ago

This answer is meant to be used as a reference

I don't recommend using IsInGroup, GetRoleInGroup or GetRankInGroup as those functions cache, meaning they'll store that data until the player joins a different/new server (if I recall correctly). However, there's an alternative to these functions: GroupService! :O I'm pretty new to it too, so please bear with me.

The group service has a function called GetGroupsAsync, where it'll return the data of the player in a specific group they're in. This can be done by doing the following:

local PlayersGroup = GroupService:GetGroupsAsync(PlayerUserId) --<Assuming that the group service has been previously defined. It'll return an array (or table) with the information of which groups the player's in.

There we go! :D We now have a function set up for the player. But now, we gotta check if the player's in the group! :O No problem there, as along with the data returned (with the array), it'll return the group's id too! :D An example of this being:

local PlayersGroup = GroupService:GetGroupsAsync(PlayerUserId)
for I, v in next, PlayersGroup do
    if v.Id == Group_Id then -- Checking if it's the specific group id, and if so it'll fire the next code block.
        -- st00f
    end
end

Yay! :D Now we'll know if the player's in the group! ^^ But now, we gotta return the information, right? No problem! The function also has that covered. (Cue sunglasses emoji). An example being:

local PlayersGroup = GroupService:GetGroupsAsync(PlayerUserId)
local RankInGroup, RoleInGroup = 0, 'Unknown'
for I, v in next, PlayersGroup do
    if v.Id == Group_Id then -- Checking if it's the specific group id, and if so it'll fire the next code block.
        RankInGroup = v.Rank --<The player's rank in the group (ranging from 1-254 if they're not the owner).
        RoleInGroup = v.Role --<Returns their role in the group.
    end
end

Now it'll return the information if the player's in the group! :D If not, it'll return 'Unknown'. :o Welp, I think this about sums it up. XP

St00f touched on but neva explained (10/10 gramm3r)

  1. GroupService - A service that returns loads of info about/with groups.

  2. Caching - In a nutshell: Where when it gets the result, it stores the data somewhere so that it can just get the data when something's prompted again. (Think of a grocery list, and how it's a go-to when shopping for dinner)

  3. GetGroupsAsync - Returns what groups a player's in, and what their role in it is. (Who they're in that group)

I hope this helped! :D If you have any questions, please let me know! ^^

Ad
Log in to vote
0
Answered by 6 years ago
Edited 6 years ago
game.Players.PlayerAdded:connect(function(player)

local leaderstats = Instance.new("IntValue") leaderstats.Name = "leaderstats" leaderstats.Value = 0

local rank = Instance.new("StringValue") rank.Name = "Rank"
rank.Parent = leaderstats

rank.Value = player:GetRoleInGroup(3975371) -- put group id in parentheses

leaderstats.Parent = player 

end)
0
Thanks for the formatting Tolly67p 0 — 6y

Answer this question