Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

I need help with a player points script?

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)

1 comment

0

http://www.roblox.com/Forum/ShowPost.aspx?PostID=131619603 There, SML said "That is why we have points. Yes, you can buy points, but I am not sure why anyone would waste the money on something that you can get for free playing games. " on page 21

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.