Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How would I make a text label update when someone buys in game cash?

Asked by 6 years ago

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)

1local P = game.Players.LocalPlayer
2local currency = P.stats.Coins.Value
3 
4while true do
5    script.Parent.Text = currency
6    wait()
7end
0
Game is also FE Asynchronize 16 — 6y
0
what is fe HavingFunStudio -23 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago
Edited 6 years ago

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:

1local P = game.Players.LocalPlayer
2local currency = P.stats.Coins --Do not include ".Value" in this because it will return an error!
3 
4currency.Changed:Connect(function()
5    script.Parent.Text = currency
6end) --This function only runs when the value has changed of the "Coins" value

If you have any questions or issues, please contact me. ;)

Ad
Log in to vote
0
Answered by 6 years ago

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

01game.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"
08end)
09local MarketplaceService = game:GetService("MarketplaceService")
10local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
11local pid = 0 --The number of the dev product
12local pid1 = 0 --The number of the dev prodcut
13MarketplaceService.ProcessReceipt = function(receiptInfo)
14 
15    for i, player in ipairs(game.Players:GetChildren()) do
View all 24 lines...

If you have any question's let me know.

Answer this question