Okay, so this is my problem, I am making a button where when you press, it's prompts the purchase of the product then afterwards awards players a certain amount of points based on the item bough. For example, 1,2,3,4, or 5 points. Here's my script. Any suggestions?
local MarketplaceService = Game:GetService("MarketplaceService") local buyButton = script.Parent local productId = 19714110 local PointsService = Game:GetService("PointsService") function buy() MarketplaceService:PromptProductPurchase(player, productId) if ( pointsToAward > 0 and universeBalance == 0) then PointsService:AwardPoints(player.userId, 1) end end buyButton.MouseButton1Down:connect(buy)
You're missing some declared variables, otherwise good try at it. It isn't recommended that players buy points however, which is against the context of Player Points.
If you want to change the number of points awarded based on what they buy, you can have your individual scripts on each button like this.
-- Needs to be a ServerScript, not Local. local MarketplaceService = Game:GetService("MarketplaceService") local PointsService = Game:GetService("PointsService") local buyButton = script.Parent local productId = 19714110 local player = script.Parent.Parent.Parent.Parent -- Parent as the player. local pointsToAward = PointsService:GetAwardablePoints() local universeBalance = PointsService:GetGamePointBalance(player.userId) buyButton.MouseButton1Click:connect(function() MarketplaceService:PromptProductPurchase(player, productId) if ( pointsToAward > 0 and universeBalance == 0) then PointsService:AwardPoints(player.userId, 1) end end)
If you one script to function multiple buttons of purchasing, then you would need to create multiple instances of buyButton.MouseButton1Click:connect(function()
with buyButton
as another variable name. It also should be in the same member of the buttons.