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

Leaderboard doesn't update when a player (re)joins?

Asked by
snewo12 72
6 years ago

Hello all! So I have this leaderboard script but it doesn't update the rank when a player got a new rank and (re)joined the game. How can I make it so it updates the rank when a player got a new rank inside the group?

Script:

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"
if player:IsInGroup(3200799) then
    rank.Value = player:GetRoleInGroup(3200799)
else
    rank.Value = "Guest"
end

leaderstats.Parent = player
rank.Parent = leaderstats
end)

Thanks in advance.

2 answers

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

Currently, Roblox caches GetRankInGroup and GetRoleInGroup on the server. To fix the cache, you could use Http Service to get the player's rank or use GroupService.Here!

Now to get the player's rank, you'd use GetGroupAsync! Here!

So you'd loop through the table and find if they're in the group. Then if they are, you'd check what rank they are in the said group and put it on the leaderboard like the following:

local GroupService = game:GetService("GroupService")
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"

    for i,v in pairs(GroupService:GetGroupsAsync(player.UserId))do
        if v.Name == "Group" then
            rank.Value = v.Role
            break
        else
            rank.Value = "Guest"
        end
    end

    leaderstats.Parent = player
    rank.Parent = leaderstats
end)

(This worked when I tested it. Tell me if something doesn't work)

0
Um where do I put my groupID lol snewo12 72 — 6y
0
You dont... you put your group name where it says group. I linked you to the wiki on how to use GetGroupAsync too... Sharkeedub 179 — 6y
0
Well, you could've been more clear. But thanks anyways. snewo12 72 — 6y
0
What do you mean be more clear? I linked you a wiki link, showed you examples, and explained it lol. How can that be more clear? Sharkeedub 179 — 6y
0
I meant the v.Name == "Group" maybe you could've add a --put the name of the group here. But it's ok.. snewo12 72 — 6y
Ad
Log in to vote
-1
Answered by 6 years ago

Simply, no datastores script. :/

0
What? snewo12 72 — 6y
0
........? 1. Not understandable 2. Should be a comment mudathir2007 157 — 6y

Answer this question