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

Give a Player Points when they buy a Developer Product?

Asked by 10 years ago

I want to make it so when a Player BUYS a Developer Product, it gives them one point. But I am stuck on the part when it gives them it when they only BUY it:

-- setup local variables
local buyButton = game.Workspace.BuyButton.SurfaceGui.TextButton
local productId = 19700135

-- when player clicks on buy brick promt him/her to buy a product
buyButton.MouseButton1Click:connect(function()

    game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)

    local PointsService = Game:GetService("PointsService")

    local pointsToAward = PointsService:GetAwardablePoints()
    local universeBalance = PointsService:GetGamePointBalance(player.userId)
    if ( pointsToAward > 0 and universeBalance == 0) then
        PointsService:AwardPoints(player.userId, 1) --Btw, do I change this to my ID?
    end
end)

PointsService.PointsAwarded:connect(function(userId, userBalanceinUni, userBalance)
    local message = Instance.new('Hint', game.Workspace)
    message.Text = "Point awarded to " .. userId .. ". This player now has " .. userBalance .. " points total!"
    wait(5)
    message:Destroy()
end)

1 answer

Log in to vote
0
Answered by 10 years ago

Here

-- setup local variables
local buyButton = game.Workspace.BuyButton.SurfaceGui.TextButton
local productId = 19700135

-- when player clicks on buy brick promt him/her to buy a product
buyButton.MouseButton1Click:connect(function()

    game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)

    local PointsService = Game:GetService("PointsService")

    local pointsToAward = PointsService:GetAwardablePoints()
    local universeBalance = PointsService:GetGamePointBalance(player.userId)
    if ( pointsToAward > 23 and universeBalance == 0) then --23 or 1 or whatever
        PointsService:AwardPoints(player.userId, 1) --Id is fine
    end
end)

PointsService.PointsAwarded:connect(function(userId, userBalanceinUni, userBalance)
    local message = Instance.new('Hint', game.Workspace)
    message.Text = "Point awarded to " .. userId .. ". This player now has " .. userBalance .. " points total!"
    wait(5)
    message:Destroy()
end)

This should work...

Ad

Answer this question