How can I add a second value/stat to my leaderstats script?

I was working on a checkpoint script from a tutorial (Bc I am a beginner scripter) , and when I finished I tried to add a second row to the leaderstats (coins, rebirth, etc.) and I just couldn’t figure out how to do it.

So, How can I add second row? Or is it even possible?

Here is the script that I was working with, I tried things like copy and pasting parts of the script or even the whole script, but none of that worked.

function oa(object)
local player = game.Players:playerFromCharacter(object)
if player ~= nil then
local ls = player.leaderstats
local sl = game.Workspace:FindFirstChild(ls.Stage.Value)
print("gah")
object.Torso.CFrame = object.Torso.CFrame + Vector3.new(0,3,0)
wait()
object.Torso.CFrame = sl.CFrame + Vector3.new(0,3,0)
end end


function oe(object)
if object.className == "Player" then
local ack = Instance.new("IntValue")
ack.Name = "leaderstats"
local ack2 = Instance.new("IntValue")
ack2.Name = "Stage"
ack2.Value = 1
ack2.Parent = ack
ack.Parent = object
end end


game.Players.ChildAdded:connect(oe)
game.Workspace.ChildAdded:connect(oa)

I hope it is possible to add another row/stat to the leaderstats with this script because this is really the only script I know that works.

Personally this is the code I use for making leaderstats as it’s relatively simple and easy to replicate.

Inside a script parented to ServerScriptService:

local Players = game:GetService("Players")

Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player
	
	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats
	
	local rebirths = Instance.new("IntValue")
	rebirths.Name = "Rebirths"
	rebirths.Parent = leaderstats
end)
1 Like

I did test it before responding and yes it does work
image

Okay, I’ll try this one out, Can you make checkpoints with it?

I’ve never tried but I don’t see any reason why it shouldn’t, if you need to access the value it’s simply player.leaderstats.whatever.value

1 Like

Thanks so much! I found another script to go along with the one u showed me and it worked for checkpoints! I just had to add this part to the end of it,

    Players.CharacterAdded:Connect(function(Character)
        repeat wait() until Character ~= nil
        local CPfolder = game.Workspace:FindFirstChild("Checkpoints")--Change "Checkpoints" to your own folder name in workspace.
        local Checkpoints = CPfolder:FindFirstChild(Stage.Value)
        Character:FindFirstChild("HumanoidRootPart").CFrame = CFrame.new(Checkpoints.Position + Vector3.new(0, 2,0))
        
        
        
        for i,ls in pairs(CPfolder:GetChildren()) do
            if ls:IsA("BasePart") then
                ls.Touched:Connect(function(Touched)
                    if Touched.Parent:WaitForChild("Humanoid") then
                        local Player = game.Players:GetPlayerFromCharacter(Touched.Parent)
                        if Player then
                            if Player.leaderstats.Stage.Value < tonumber(ls.Name) then
                                Player.leaderstats.Stage.Value = tonumber(ls.Name)
                            end
                        end
                    end
                end)
            end
        end
        
    end)
end)