I've been trying to make a script that changes the player's rank on the leaderboard according to the player's team. It uses group IDs and role values to change the player's rank accordingly. So for example, if my team was "Army", the script would grab my rank from the group and change my rank on the leaderboard according to my rank in the group. If I was switching from the "Army" team to "Marines", the script would grab my rank from the Marines group and change my rank to my rank in the Marines group.

Here's what I got, I don't know why it's not working:

local playerStats = {}

local TeamsService = game:GetService("Teams")

game.Players.PlayerAdded:connect(function(player)
	local leaderstats = Instance.new("Model", player)
	leaderstats. Name = "leaderstats"
	local grouprank = Instance.new("StringValue", leaderstats)
	grouprank.Name = "Rank"
	
	local teamName = "Civilians"
	
	for _, team in pairs(TeamsService:GetTeams()) do
		team.PlayerAdded:connect(function(player)
			print(player.Name.. " has joined " ..team.Name)
			if teamName == "Army" then
				local rank = player:GetRoleInGroup(165491)
				if rank ~= 0 then
					grouprank.Value = rank
				else
					grouprank.Value = "Guest"
				end
			end
		
			if teamName == "Marines" then
				local rank = player:GetRoleInGroup(4187067)
				if rank ~= 0 then
					grouprank.Value = rank
				else
					grouprank.Value = "Guest"
				end
			end
		end)
	end

	playerStats[player] = leaderstats
	player.TeamColor = game.Teams[teamName].TeamColor
end)

2 comments

0

is this a server script or local script?

0

I have it as a server script.