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

How can I be able to make this script award 50 points?

Asked by 10 years ago

How can I make this script be able to award a player 50 points after the player has bought this??

local player = script.Parent.Parent.Parent.Parent.Parent.Parent
print(player)
 local MarketplaceService = Game:GetService("MarketplaceService")
local buyButton = script.Parent
local productId = 20792308

buyButton.MouseButton1Click:connect(function()
    MarketplaceService:PromptProductPurchase(player, productId)
end)

local MarketplaceService = Game:GetService("MarketplaceService")

MarketplaceService.ProcessReceipt = function(receiptInfo)
    print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)
    wait(1)
    player:FindFirstChild("leaderstats").Points = player:FindFirstChild("leaderstats").Points + 50
    -- ...
    -- use DataStore to record purchase
    -- ...  
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end
0
Using `FindFirstChild` without error checking is stupid -- it misleads the reader into thinking you do error check, yet will your code will error anyway. `.leaderstats` suffices. BlueTaslem 18071 — 10y
0
Ok, so how do I fix it then. It still errors without it. billybobtijoseph 1 — 10y

3 answers

Log in to vote
0
Answered by 10 years ago

13:17:41 -- Players.billybobtijoseph.PlayerGui.Shop.Page1.BuyPointsFrame.Button1: 16: attempt to perform arithmetic on field 'Points' (a userdata value)

Ad
Log in to vote
0
Answered by 10 years ago

Replace the line:

 player:FindFirstChild("leaderstats").Points = player:FindFirstChild("leaderstats").Points + 50

with:

 player:FindFirstChild("leaderstats").Points.Value = player:FindFirstChild("leaderstats").Points.Value + 50

You're using value holder objects. You set their values through their Value property.

Log in to vote
0
Answered by
Lacryma 548 Moderation Voter
10 years ago

What you're actually asking it to add is userdata not a number. The solution is to add .Value towards the end since you cannot perform arithmetic on this.

local player = script.Parent.Parent.Parent.Parent.Parent.Parent
print(player)
 local MarketplaceService = Game:GetService("MarketplaceService")
local buyButton = script.Parent
local productId = 20792308

buyButton.MouseButton1Click:connect(function()
    MarketplaceService:PromptProductPurchase(player, productId)
end)

local MarketplaceService = Game:GetService("MarketplaceService")

MarketplaceService.ProcessReceipt = function(receiptInfo)
    print(receiptInfo.PlayerId .. " just bought " .. receiptInfo.ProductId)
    wait(1)
    --Fixed it here
    player:FindFirstChild("leaderstats").Points.Value = player:FindFirstChild("leaderstats").Points.Value + 50
    -- ...
    -- use DataStore to record purchase
    -- ...  
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

Answer this question