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

Help with a script that gives points

Asked by 10 years ago

This coding is in the Developer product script. When I buy the product, I want +100 points (in my game its named Credits) to my credits leaderstats. Though, it will not give me 100 points, and since you cannot purchase something in edit mode, I cant check the output window. So, heres my coding. player = game.Players:GetPlayerFromCharacter() points = player.leaderstats.Credits points.Value = points.Value + 100 --This is the coding I added into the script. This is what I want to happen when I purchase the script. Heres all of the code --setup local variables local MarketplaceService = Game:GetService("MarketplaceService") local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") local productId = "19323757"

-- define function that will be called when purchase finished MarketplaceService.ProcessReceipt = function(receiptInfo)

-- find the player based on the PlayerId in receiptInfo
for i, player in ipairs(game.Players:GetChildren()) do
    if player.userId == receiptInfo.PlayerId then

        -- check which product was purchased
        if receiptInfo.ProductId == productId then

            -- handle purchase. In this case we are healing the player.
            player = game.Players:GetPlayerFromCharacter()
            points = player.leaderstats.Credits
            points.Value = points.Value + 100

            -- more feedback for the player.
            game.Workspace.DisplayScreen.SurfaceGui.TextBox.Text = player.Name .. " has purchased a healing potion."
        end
    end
end 

-- record the transaction in a Data Store
local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId
ds:IncrementAsync(playerProductKey, 1)  

-- tell ROBLOX that we have successfully handled the transaction
return Enum.ProductPurchaseDecision.PurchaseGranted     

end

1
I just made an automated consumables GUI for this, you can examine it or use it. ; http://www.roblox.com/Automated-Consumables-Dev-product-creating-GUI-scr-item?id=150280310 Azarth 3141 — 10y
1
Thanks Azarth trogyssy 221 — 10y
0
yeah, good job Azrath! :D 1JBird1 64 — 3y

Answer this question