I have developer products that people can buy for in game cash. In stead of a leader board, i have a text label that shows the amount of cash someone has. Heres the script: (this is in a localscript)
local P = game.Players.LocalPlayer local currency = P.stats.Coins.Value while true do script.Parent.Text = currency wait() end
The simple answer is easy: Use the ".Changed" event! It's useful for these various things and is used when a value changes (either a "BoolValue", "Color3Value", "IntValue", etc. has changed; It's used when something like your "currency's" value has changed).
Here would be the simple remake of your script:
local P = game.Players.LocalPlayer local currency = P.stats.Coins --Do not include ".Value" in this because it will return an error! currency.Changed:Connect(function() script.Parent.Text = currency end) --This function only runs when the value has changed of the "Coins" value
If you have any questions or issues, please contact me. ;)
You could make a Intvalue inside the player to make it so when the player buys the dev product it adds the money to the int value then it goes through the script to the text label you want
game.Players.PlayerAdded:Connect(function(plr) local leaderstats = Instance.new("Folder", plr) leaderstats.Name = "leaderstats" local money = Instance.new("IntValue", leaderstats) money.Name = "Money" end) local MarketplaceService = game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local pid = 0 --The number of the dev product local pid1 = 0 --The number of the dev prodcut MarketplaceService.ProcessReceipt = function(receiptInfo) for i, player in ipairs(game.Players:GetChildren()) do if player.userId == receiptInfo.PlayerId then if receiptInfo.ProductId == pid then player.leaderstats.Money.Value = player.leaderstats.Money.Value + 1000 elseif receiptInfo.ProductId == pid1 then player.leaderstats.Money.Value = player.leaderstats.Money.Value + 6000 end end end end
If you have any question's let me know.