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.
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)
Simply, no datastores script. :/