How can I let 2 leader stats appear?

Hey everyone I’m currently working on a leader stats system and rn I have 2 leader stats I want to show but it only shows one.Btw. ima show the 2 mini Scripts rn(Can y’all also let the Wins leader stat have the same save system like the Cash leader stat?

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

	local wins = Instance.new("IntValue", leaderstats)
	wins.Name = "Wins"
	wins.Value = 100
end)







local dss = game:GetService("DataStoreService")
local ds = dss:GetDataStore("DATA")

local mps = game:GetService("MarketplaceService")

local devProducts = require(game:GetService("ReplicatedStorage"):WaitForChild("DeveloperProducts"))


function saveData(plr:Player)
	
	if not plr:FindFirstChild("DATA FAILED TO LOAD") then
		
		local plrCash = plr.leaderstats.Cash.Value
		
		local success, err = nil, nil
		
		while true do
			
			success, err = pcall(function()
				ds:SetAsync(plr.UserId .. " - Cash", plrCash)
			end)
			
			if not success then
				warn(err)
				task.wait(0.01)
			else
				break
			end
		end
	end
end

function loadData(plr:Player)
	
	local dataFailedWarning = Instance.new("StringValue")
	dataFailedWarning.Name = "DATA FAILED TO LOAD"

	local success, plrData = nil, nil
	
	while true do
		success, plrData = pcall(function()
			return ds:GetAsync(plr.UserId .. " - Cash")
		end)
		task.wait(0.02)
		if not success then
			dataFailedWarning.Parent = plr
			warn(plrData)
		else
			break
		end
	end
	dataFailedWarning:Destroy()
	
	return plrData
end

function setupLeaderstats(plr:Player, savedCash:number)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = savedCash or 0
	cash.Parent = leaderstats
	
	
	local cash = Instance.new("IntValue")
	cash.Name = "Wins"
	cash.Value = savedCash or 0
	cash.Parent = leaderstats
end

function handlePurchase(purchaseInfo)
	
	local plr = game.Players:GetPlayerByUserId(purchaseInfo.PlayerId)
	
	if not plr or plr:FindFirstChild("DATA FAILED TO LOAD") then
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
	
	local productID = purchaseInfo.ProductId
	
	if devProducts[productID] then
		plr.leaderstats.Cash.Value += devProducts[productID].Cash
		
		return Enum.ProductPurchaseDecision.PurchaseGranted
		
	else
		return Enum.ProductPurchaseDecision.NotProcessedYet
	end
end


game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
	for _, plr in pairs(game.Players:GetPlayers()) do
		saveData(plr)
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	
	local plrData = loadData(plr)
	setupLeaderstats(plr, plrData)
end)





mps.ProcessReceipt = handlePurchase

Why do you need two leaderstats exactly? Can’t you just combine them into one leaderstats? In my opinion, one seems more logical and easier than using two.

Ye I just want both to appear on my Screen Wins and Cash it doesn’t matter how they but I tried putting them together but I’m noob Scripter I even watched tut

Alright, I think I understand. You really don’t need two though, so just used this leaderstats creator only:

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

	local wins = Instance.new("IntValue", leaderstats)
	wins.Name = "Wins"
	wins.Value = 100
	
	local Cash = Instance.new("IntValue", leaderstats)
	Cash.Name = "Cash"
	Cash.Value = 100
end)

1 Like

-- Script to create leaderstats for Points and Coins

game.Players.PlayerAdded:Connect(function(player)
    -- Create the leaderstats folder
    local leaderstats = Instance.new("Folder")
    leaderstats.Name = "leaderstats"
    leaderstats.Parent = player

    -- Create the Points value
    local points = Instance.new("IntValue")
    points.Name = "Points"
    points.Value = 0 -- Initial value
    points.Parent = leaderstats

    -- Create the Coins value
    local coins = Instance.new("IntValue")
    coins.Name = "Coins"
    coins.Value = 0 -- Initial value
    coins.Parent = leaderstats
end)

1 Like

Thank y’all but rn it doesn’t save the cash anymore why?
I replaced it with this code

function setupLeaderstats(plr:Player, savedCash:number)
	
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = plr
	
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Value = savedCash or 0
	cash.Parent = leaderstats
	
	
	local cash = Instance.new("IntValue")
	cash.Name = "Wins"
	cash.Value = savedCash or 0
	cash.Parent = leaderstats
end

I figured out its because of this line function setupLeaderstats(plr:Player, savedCash:number)
how do I change it because where I changed it with this line only 1 appeared again

Yes you are save cash good Luck