Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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)

5 comments

0

Um where do I put my groupID lol

0

You dont... you put your group name where it says group. I linked you to the wiki on how to use GetGroupAsync too...

0

Well, you could've been more clear. But thanks anyways.

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?

0

I meant the v.Name == "Group" maybe you could've add a --put the name of the group here. But it's ok..

Simply, no datastores script. :/

2 comments

0

What?

0

........? 1. Not understandable 2. Should be a comment

This discussion is preserved as it was. New answers, comments, and votes are closed.