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

What is wrong with my leaderboard?

What I am trying to do is if the player is in a group, a stat will show up as their rank in the group, if they are not in the group.. their stat will be "Guest". At the same time I am trying to make it so if they are in a certain rank in the group they will be on the team Bright Red, or team name DJ.

I don't see why this does not work except I may have assigned the players team incorrectly..

local playerStats = {} --this keeps a list of the stats for each player that enters the game
 
 game.Players.PlayerAdded:connect(function(player) --Added function
     local leaderstats = Instance.new("Model", player) --Make leadeerstats
     leaderstats.Name = "leaderstats" --Change the name...
 
     local grouprank = Instance.new("StringValue", leaderstats) --assign the variable
     grouprank.Name = "Rank" --set up value
	 local rank = player:GetRoleInGroup(1066846) --Get the group rank from group
	
     if rank ~= 0 then --If user is in group...
		 grouprank.Value = rank --Then assign them the rank
 	 else
		grouprank.Value = "Guest" --They are not in group so they get this rank on the leaderboard
	 end
		if rank ~= 75 then --If user is rank number 75, assign them to team name DJ
		local team = game:GetService("Teams") --Get the Team service
		player.team = DJ --Change the players team to DJ, Should I do team color? problem could be right here
     playerStats[player] = leaderstats 
	 end
end)

1 answer

✓ Accepted answer

It doesn't work because you got the ROLE of the player, not the number rank, so you can make another variable for the number rank like this:

local Nrank= player:GetRankInGroup(1066846)

Then instead of using 'rank' to determine the team they should be on, use this. But keep rank for the string ranking. nrank will be used instead, and rank will be used to give them the role they have, if they are not in the group, it will put them as guest anyways.

Fixed:


 game.Players.PlayerAdded:connect(function(player) --Added function
     local leaderstats = Instance.new("Model", player) --Make leaderstats
     leaderstats.Name = "leaderstats" --Change the name...

     local grouprank = Instance.new("StringValue", leaderstats) --assign the variable
     grouprank.Name = "Rank" --set up value
     local rank = player:GetRoleInGroup(1066846) --Get the group rank from group
	local nrank=player:GetRankInGroup(1066846)
	grouprank.Value=rank
        if nrank == 75 then --If user is rank number 75, assign them to team name DJ
        player.TeamColor = BrickColor.new("Cyan")--Or color of the team 'DJ'
     end
end)

6 comments

0

When I tested it, it did not make me on the team.

0

are you above number rank 75?

0

I changed it to a lower number when I tested it.

0

hmm

0

I know why it did not work, it was my mistake. I left this in somehow... playerStats[player] = leaderstats

0

okay

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