How can i have two leaderstats

Hi there. I was just wondering how i could have two leaderstats i have an script here but i dont know how i could put another leaderstat in that script bc if i do or it will be the stage leaderstat that shows up or the other leaderstat that shows up but i cant have it both could u help me?
Here is the script :

local dss = game:GetService(“DataStoreService”)
local obbyDS = dss:GetDataStore(“ObbyData”)

local checkpoints = workspace.Stages

game.Players.PlayerAdded:Connect(function(plr)

local obbyData = obbyDS:GetAsync(plr.UserId .. "-obbyStageProgress")

local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = plr

local stage = Instance.new("StringValue")
stage.Name = "Stage"
stage.Value = obbyData or 1
stage.Parent = ls


local char = plr.Character or plr.CharacterAdded:Wait()

char:waitForChild("HumanoidRootPart"):GetPropertyChangedSignal("CFrame")

char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[stage.Value].CFrame

char.Humanoid.Touched:Connect(function(touch)

	if touch.Parent == checkpoints then
		if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or touch.Name == "End" then
			stage.Value = touch.Name

			pcall(function()

				obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
			end)
		end
	end
end)

plr.CharacterAdded:Connect(function(char)

	local hrp = char:WaitForChild("HumanoidRootPart")       
	local humanoid = char:WaitForChild("Humanoid")

	hrp:GetPropertyChangedSignal("CFrame"):Wait()

	hrp.CFrame = checkpoints[stage.Value].CFrame

	humanoid.Touched:Connect(function(touch)

		if touch.Parent == checkpoints then
			if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or touch.Name == "End" then
				stage.Value = touch.Name

				pcall(function()

					obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
				end)
			end
		end
	end)
end)    

end)

game.Players.PlayerRemoving:Connect(function(plr)

pcall(function()

	obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
end)

end)

1 Like

Have you tried to put multiple values into the leaderstats folder?

Where can i find the leadersat folder?
.

In the player. If you made values for the player in different scripts, then in the scripts, add this:

local leaderstats = player:WaitForChild("leaderstats")
-- create values

which ever leaderstats folder was created first, it will only display the values in it on the player list.

1 Like

And where should i put that script in the beginning of the other script or the end

Anywhere after the folder is created, just add values to it like you did for stage

Well, you can only add that if you have multiple scripts. If you do, you would place the code in the section of the script where it creates another leaderstats folder

Here try this out:

Example Code
local dss = game:GetService(“DataStoreService”)
local obbyDS = dss:GetDataStore(“ObbyData”)

local checkpoints = workspace.Stages

game.Players.PlayerAdded:Connect(function(plr)

local obbyData = obbyDS:GetAsync(plr.UserId .. "-obbyStageProgress")

local ls = Instance.new("Folder")
ls.Name = "leaderstats"
ls.Parent = plr

local newLeader = Instance.new("StringValue") -- If its number then put NumberValue
newLeader.Name = "Put name here"
newLeader.Value = "Value"
newLeader.Parent = Is

local stage = Instance.new("StringValue")
stage.Name = "Stage"
stage.Value = obbyData or 1
stage.Parent = ls


local char = plr.Character or plr.CharacterAdded:Wait()

char:waitForChild("HumanoidRootPart"):GetPropertyChangedSignal("CFrame")

char:WaitForChild("HumanoidRootPart").CFrame = checkpoints[stage.Value].CFrame

char.Humanoid.Touched:Connect(function(touch)

	if touch.Parent == checkpoints then
		if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or touch.Name == "End" then
			stage.Value = touch.Name

			pcall(function()

				obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
			end)
		end
	end
end)

plr.CharacterAdded:Connect(function(char)

	local hrp = char:WaitForChild("HumanoidRootPart")       
	local humanoid = char:WaitForChild("Humanoid")

	hrp:GetPropertyChangedSignal("CFrame"):Wait()

	hrp.CFrame = checkpoints[stage.Value].CFrame

	humanoid.Touched:Connect(function(touch)

		if touch.Parent == checkpoints then
			if (tonumber(touch.Name) and tonumber(touch.Name) > tonumber(stage.Value)) or touch.Name == "End" then
				stage.Value = touch.Name

				pcall(function()

					obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
				end)
			end
		end
	end)
end)   
end)

game.Players.PlayerRemoving:Connect(function(plr)

pcall(function()
obbyDS:SetAsync(plr.UserId .. "-obbyStageProgress", plr.leaderstats.Stage.Value)
end)

end)

More:

https://education.roblox.com/en-us/resources/adventure-game-creating-a-leaderboard

Just simply do this?

     game.Players.PlayerAdded:Connect(function(plr)
            local obbyData = obbyDS:GetAsync(plr.UserId .. "-obbyStageProgress")

            local ls = Instance.new("Folder")
            ls.Name = "leaderstats"
            ls.Parent = plr

            local stage = Instance.new("StringValue")
            stage.Name = "Stage"
            stage.Value = obbyData or 1
            stage.Parent = ls

            local AnotherStat = Instance.new("IntValue")
            AnotherStat .Name = "AnotherStat "
            AnotherStat .Value = 0
            AnotherStat .Parent = ls
      
        end)

Hey! I understand your problem, all you need to do is add another value, just like you did with stages, and parent it under leaderstats which can be found under the player!

Please keep in mind the name of the value will be the name showed on the leaderstats and its value will be it’s content. If you have any questions, feel free to let me know.

But if the leaderstat is cash doesnt it need to be an IntValue

IntValue accepts negative and positive numbers while NumberValue accepts what IntValue accepts with the addition of decimals.

Thx for explaining. The scripts still dont work

1 Like