Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why doesn't my leaderstat update until I rejoin the game?

Hello! My leaderstat for Most purchased items in game is now working, but it doesn't update until I quit and rejoin the game-

Any advice or suggestions on what I can do to allow this script to update real time?

Thanks.

local marketPlaceService = game:GetService("MarketplaceService")
local playerOwnsAsset = marketPlaceService.PlayerOwnsAsset
	 
local Players = game:GetService("Players")
 
local Clothes = {
    123456;
    1234567;    }
 
Players.PlayerAdded:Connect(function(Plr)
    local Statistics = Instance.new("Folder")
    Statistics.Name = "leaderstats"
    Statistics.Parent = Plr
 
    local Bought = Instance.new("IntValue")
    Bought.Name = "Bought"
    Bought.Value = 0
    Bought.Parent = Statistics
 
     for _, itemID in ipairs(Clothes) do
        local success, purchasedItem = pcall(playerOwnsAsset, marketPlaceService, Plr, itemID)
 
        if purchasedItem then
            Bought.Value = Bought.Value + 1
        end
    end
end)

Note: I used placeholders instead of the actual clothing ID's for demonstration purposes only. Any help would be greatly appreciated!

Thanks.

1 answer

you can use the PromptPurchaseFinished event to update the Bought value whenever the player purchases an item

marketPlaceService.PromptPurchaseFinished:Connect(function(player, assetId, wasPurchased)
	if wasPurchased and table.find(Clothes, assetId) then
		player.leaderstats.Bought.Value += 1
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.