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.
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)