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)

local P = game.Players.LocalPlayer
local currency = P.stats.Coins.Value

while true do
    script.Parent.Text = currency
    wait()
end
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:

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

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

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.

Answer this question