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

Different group for each team leaderboard script?

I want to make it so that my script changes the group it gets the ranks from when a player switches teams. For example, if I was on the team "Really Black" and it shows my rank in the leaderboard for group A and I switch to the "Really Red" team, I want to change my script so that instead of getting my rank from group A, it gets it from group B instead. How would I do that? Here is my code so far:

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"
rank.Value = player:GetRoleInGroup(5439395) -- put group id in parentheses

leaderstats.Parent = player
rank.Parent = leaderstats

end)

1 comment

0

Elaborate on your question, please.

3 answers

✓ Accepted answer

First, you define both groups (groupA and groupB) Then, you define both Teams (Team1 and Team2)

After that, you just use Team.PlayerAdded to check if they joined the team, and change their rank accordingly.

local Teams = game:GetService("Teams")
local Team1 = Teams["TEAM 1 NAME HERE"]
local Team2 = Teams["TEAM 2 NAME HERE"]

game.Players.PlayerAdded:connect(function(player)

local groupA = 5439395 -- assuming the ID you put is group A
local groupB = 1111111 -- put ID of group B here

local leaderstats = Instance.new("IntValue")
leaderstats.Name = "leaderstats"
leaderstats.Value = 0

local rank = Instance.new("StringValue")
rank.Name = "Rank"
rank.Value = player:GetRoleInGroup(groupA)

leaderstats.Parent = player
rank.Parent = leaderstats

end)

Team1.PlayerAdded:Connect(function(plr)
      local stats = plr:WaitForChild("leaderstats")
      local rank = stats:WaitForChild("Rank")

      rank.Value = plr:GetRoleInGroup(groupA)
end)

Team2.PlayerAdded:Connect(function(plr)
      local stats = plr:WaitForChild("leaderstats")
      local rank = stats:WaitForChild("Rank")

      rank.Value = plr:GetRoleInGroup(groupB)
end)

Tbh, I don't know how to fix this. Atleast try to convert the value to a string.

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"
rank.Value = tostring(player:GetRoleInGroup(5439395)) -- put group id in parentheses

leaderstats.Parent = player
rank.Parent = leaderstats

end)

String Values won't accept other values. You would need to change it into a string using tostring().

local Teams = game:GetService("Teams")
local Team1 = Teams["TEAM 1 NAME HERE"]
local Team2 = Teams["TEAM 2 NAME HERE"]

local groupA, groupB, leaderstats, rank

game.Players.PlayerAdded:connect(function(player)

    groupA = 5439395 -- assuming the ID you put is group A
    groupB = 1111111 -- put ID of group B here

    leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"

    rank = Instance.new("StringValue")
    rank.Name = "Rank"
    rank.Value = player:GetRoleInGroup(groupA)

    leaderstats.Parent = player
    rank.Parent = leaderstats
    
    player.CharacterAdded:Connect(function(char)
        if player.Team == Team1 then
            rank.Value = player:GetRoleInGroup(groupA)
        elseif player.Team == Team2 then
            rank.Value = player:GetRoleInGroup(groupB)
        end
    end)
end)

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