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
13:17:41 -- Players.billybobtijoseph.PlayerGui.Shop.Page1.BuyPointsFrame.Button1: 16: attempt to perform arithmetic on field 'Points' (a userdata value)
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.
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