Im making a leaderstats for clothes purchased and time spent. Time spent works but purchase count doesn't.
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(60)
player.leaderstats.Time.Value = player.leaderstats.Time.Value + 1
end
end
game.Players.PlayerAdded:Connect(addTime)
you buy the clothes from a mannequin with this code (not a local script)
local CLICK_BLOCK = script.Parent
local ITEM_ID = 5333151672 --ID number of shirt
local Click = Instance.new("ClickDetector",CLICK_BLOCK)
Click.MouseClick:connect(function(p)
game:GetService("MarketplaceService"):PromptPurchase(p,ITEM_ID)
player.leaderstats.PurchaseCount.Value = player.leaderstats.PurchaseCount.Value + 1
end)
tysm for helping

2 comments
This has a big flaw. You don't have to actually purchase the item, you just have to click it. You will still have a bigger purchase count if you press "cancel"
so how would it only add value when bought?