This is a leaderboard for my homestore to see how much time a player spent and how much they bought.

Everything works besides purchase count

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("TimeSaveSystem")
local ds2 = datastore:GetDataStore("PurchaseCountSaveSystem")

game.Players.PlayerAdded:connect(function(plr)
 local folder = Instance.new("Folder", plr)
 folder.Name = "leaderstats"
 local Time = Instance.new("IntValue", folder)
 Time.Name = "Time"
 local PurchaseCount = Instance.new("IntValue", folder)
 PurchaseCount.Name = "PurchaseCount"

 Time.Value = ds1:GetAsync(plr.UserId) or 0
 ds1:SetAsync(plr.UserId, Time.Value)

 PurchaseCount.Value = ds2:GetAsync(plr.UserId) or 0
 ds2:SetAsync(plr.UserId, PurchaseCount.Value)

 Time.Changed:connect(function()
  ds1:SetAsync(plr.UserId, Time.Value)
 end)

 PurchaseCount.Changed:connect(function()
  ds2:SetAsync(plr.UserId, PurchaseCount.Value)
 end)
end)

local function addTime(player)
    while true do
        wait(1)
        player.leaderstats.Time.Value = player.leaderstats.Time.Value + 1
    end
end

game.Players.PlayerAdded:Connect(addTime)

local PurchaseCount = 0

Tysm for helping!!

2 comments

0

Where's the script for changing the purchase count?

0

local PurchaseCount = 0 --Check if player purchased PurchaseCount.Value = PurchaseCount.Value + 1