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)
1 | local P = game.Players.LocalPlayer |
2 | local currency = P.stats.Coins.Value |
3 |
4 | while true do |
5 | script.Parent.Text = currency |
6 | wait() |
7 | 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:
1 | local P = game.Players.LocalPlayer |
2 | local currency = P.stats.Coins --Do not include ".Value" in this because it will return an error! |
3 |
4 | currency.Changed:Connect( function () |
5 | script.Parent.Text = currency |
6 | 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
01 | game.Players.PlayerAdded:Connect( function (plr) |
02 |
03 | local leaderstats = Instance.new( "Folder" , plr) |
04 | leaderstats.Name = "leaderstats" |
05 |
06 | local money = Instance.new( "IntValue" , leaderstats) |
07 | money.Name = "Money" |
08 | end ) |
09 | local MarketplaceService = game:GetService( "MarketplaceService" ) |
10 | local ds = game:GetService( "DataStoreService" ):GetDataStore( "PurchaseHistory" ) |
11 | local pid = 0 --The number of the dev product |
12 | local pid 1 = 0 --The number of the dev prodcut |
13 | MarketplaceService.ProcessReceipt = function (receiptInfo) |
14 |
15 | for i, player in ipairs (game.Players:GetChildren()) do |
If you have any question's let me know.