So I want to make my friend's group a leaderboard that shows the person's division, i.e. another group, and then the rank of that group. I have this script, but when I start I see the leaderstats on the leaderboard but they do not fill in. I am in the first group on the list and it is still empty. It's in a regular script placed in ServerScriptService.
game.Players.PlayerAdded:connect(function(player) local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats" leaderstats.Value = 0 leaderstats.Parent = player local allegiance = Instance.new("StringValue") allegiance.Name = "Allegiance" allegiance.Value = "None" allegiance.Parent = leaderstats local rank = Instance.new("StringValue") rank.Name = "Rank" rank.Value = "None" rank.Parent = leaderstats --v----DDR/Divisions
if player:IsInGroup(3120627) then allegiance.Value = "DDR Volk." rank.Value = player:GetRoleInGroup(3120627)
elseif player:IsInGroup(2536151) then allegiance.Value = "DDR Grenz." rank.Value = player:GetRoleInGroup(2536151)
--v----SAF/Divisions
elseif player:IsInGroup(2971335) then allegiance.Value = "SAF" rank.Value = player:GetRoleInGroup(2971335)
elseif player:IsInGroup(3294006) then allegiance.Value = "SAF Airborne" rank.Value = player:GetRoleInGroup(3294006)
elseif player:IsInGroup(3279476) then allegiance.Value = "SAF Airforce" rank.Value = player:GetRoleInGroup(3279476)
elseif player:IsInGroup(3279454) then allegiance.Value = "SAF KGB" rank.Value = player:GetRoleInGroup(3279454)
elseif player:IsInGroup(3120627) then allegiance.Value = "SAF Armor" rank.Value = player:GetRoleInGroup(3120627) end
leaderstats.Parent = player
end)
This would be the proper way of handling it:
local values = { {3120627, "DDR Volk."}, {2536151, "DDR Grenz."}, {2971335, "SAF"}, {3294006, "SAF Airborne"}, {3279476, "SAF Airforce"}, {3279454, "SAF KGB"}, {3120627, "SAF Armor"} } game:GetService("Players").PlayerAdded:connect(function(player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Value = 0 local allegiance = Instance.new("StringValue") allegiance.Name = "Allegiance" allegiance.Value = "None" allegiance.Parent = leaderstats local rank = Instance.new("StringValue") rank.Name = "Rank" rank.Value = "None" rank.Parent = leaderstats leaderstats.Parent = player for i = 1,#values do if player:IsInGroup(values[i][1]) then allegiance.Value = values[i][2] rank.Value = player:GetRoleInGroup(values[i][1]) end end end