[Scripting Help] How would I have multiple items on a leaderboard?

Q: How would I have multiple items on a leaderboard?

Hey, I’m Carlos and I’m having a little problem. I want to have a Minutes played leaderboard as well as their group rank leaderboard but it only shows their rank and not minutes. I would like to know if there is any way I can show both and not just one I will provide a picture below!

I have tried to look on here but no luck.

So something like this but instead of purchases, it would be time played.
Screen Shot 2020-11-07 at 11.15.31 PM

Also since I know nothing about scripting I used these free models

6 Likes

I’m assuming you have two scripts for each leaderboard. If so then its most likely that each script is creating a “leaderstats” folder/instance. This results in two leaderstats objects in the actual player, and so the game is just picking one of those and not the other.

What you need to do is have 1 leaderstats object and place all your values inside that one.

1 Like

Yes, I agree with @Ze_tsu. You would have to Instantiate (create a new value) in the same script as the one where you create the leaderstats.

game.Players.PlayerAdded:Connect(function(player)
	local Leaderstats = Instance.new("Folder", player)
	Leaderstats.Name = "leaderstats"

	local variableName = Instance.new("IntValue", Leaderstats)
	variableName.Name = "nameOfVariable"
end)

Is this what you mean? If so it does not work. I just copied on of the scripts and pasted it in to the other script.

game.Players.PlayerAdded:Connect(function(p)
local L = Instance.new(‘Folder’,p)
L.Name = ‘leaderstats’
local stats = Instance.new(‘StringValue’,L)
stats.Name = ‘Rank’
stats.Value = p:GetRoleInGroup(8128398) – Replace 3716701 with your Group ID
end)

local DataStoreService = game:GetService(“DataStoreService”)
local DataStore = DataStoreService:GetDataStore(“TimeStats”)

game.Players.PlayerAdded:Connect(function(Player)
local Leaderstats = Instance.new(“Folder”)
Leaderstats.Name = “leaderstats”
Leaderstats.Parent = Player
local Minutes = Instance.new(“IntValue”)
Minutes.Name = “Minutes”
Minutes.Value = 0
Minutes.Parent = Leaderstats

local Data = DataStore:GetAsync(Player.UserId)
if Data then
	Minutes.Value = Data
end

coroutine.resume(coroutine.create(function()
	while true do
		wait(60)
		Minutes.Value = Minutes.Value + 1
	end
end))

end)

game.Players.PlayerRemoving:Connect(function(Player)
DataStore:SetAsync(Player.UserId, Player.leaderstats.Minutes.Value)
end)

Is this what you mean? If so it does not work. I just copied on of the scripts and pasted it in to the other script.

2 Likes

I did some small edits to the script you provided so try this:

-- Services --
local PS = game:GetService("Players");

-- Variables --
local GroupId = 3716701;
local DataStoreService = game:GetService("DataStoreService");
local DataStore = DataStoreService:GetDataStore("TimeStats");

-- Connections --
PS.PlayerAdded:Connect(function(Player)
    local Leaderstats = Instance.new("Folder");
    Leaderstats.Name = "leaderstats";
	Leaderstats.Parent = Player;
	
    local Minutes = Instance.new("IntValue");
    Minutes.Name = "Minutes";
    Minutes.Value = 0;
	Minutes.Parent = Leaderstats;
	
	local Rank = Instance.new("StringValue");
	Rank.Name = "Rank";
	Rank.Value = Player:GetRoleInGroup(GroupId);
	Rank.Parent = Leaderstats;
    
    local Data = DataStore:GetAsync(Player.UserId);
    if Data then
        Minutes.Value = Data;
    end;
    
    coroutine.resume(coroutine.create(function()
        while true do
            wait(60)
            Minutes.Value = Minutes.Value + 1
        end
    end));
end);

PS.PlayerRemoving:Connect(function(Player)
    DataStore:SetAsync(Player.UserId, Player.leaderstats.Minutes.Value);
end);
4 Likes

No, do not just copy paste the scripts into the same one. Identify the parts that are the same and don’t repeat them. You are using two player Added functions, when you only need one.

2 Likes

It worked! Thank you for your help! :slight_smile:

1 Like