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

Well, need help with Player Points and Developer Products?

Okay, I am trying to make a player points store, original, yes I know. I'm broke though so, aha. I'm trying to have it where when you click the button, it brings up the purchase, then rewards points after the points are purchased.

Could you help me with the code? Here is on for the script:

local buyButton = script.Parent 
local productId = 19714128  
local Player = script.Parent.Parent.Parent.Parent.Parent

Type = 0 
if Player.Name == "Asirix" then Type = 2 else Type = 0 end 
buyButton.MouseButton1Click:connect(function() 
    Game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId, false,  Type) 
end) 

local MarketplaceService = Game:GetService("MarketplaceService") 
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory") 

MarketplaceService.ProcessReceipt = function(receiptInfo) 
	
	
for i, player in ipairs(game.Players:GetChildren()) do 
        if player.userId == receiptInfo.PlayerId then 
            if receiptInfo.ProductId == productId then 
			local pointsToAward = PointsService:GetAwardablePoints()
			local universeBalance = PointsService:GetGamePointBalance(player.userId)
			if ( pointsToAward > 0 and universeBalance == 0) then
		PointsService:AwardPoints(player.userId, 10)
	end
end
end
end


local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId 
    ds:IncrementAsync(playerProductKey, 1)   
    return Enum.ProductPurchaseDecision.PurchaseGranted      
end 

I need help, this is a local script under a gui button.

1 answer

Get a ScreenGUI, put a Frame in the ScreenGUI, then put a Text Button in the Frame. Then put this script into a script which is in the frame:

productId = IDHERE
Player=script.Parent.Parent.Parent.Parent.Parent
local MarketplaceService = Game:GetService("MarketplaceService")
function UsernameFromID(ID)
	if type(ID) ~= "number" then
	return
	end
	local sets = game:service("InsertService"):GetUserSets(ID)
	for k, v in next, sets do
		if v.Name == "My Models" then
			return v.CreatorName
		end
	end
end
function giveRewards(player)
if Player:findFirstChild("leaderstats") then
Player.leaderstats[script.Parent.Currency.Value].Value=Player.leaderstats[script.Parent.Currency.Value].Value+tonumber(script.Parent.Cost.Value)
end
	return Enum.ProductPurcaseDecision.PurchaseGranted
end
MarketplaceService.ProcessReceipt = function(receiptInfo)
	giveRewards(UsernameFromID(receiptInfo.PlayerId))
end
script.Parent.MouseButton1Down:connect(function()
	Game:GetService("MarketplaceService"):PromptProductPurchase(script.Parent.Parent.Parent.Parent.Parent, productId)
end)

Now, when you press the button, it should prompt you to buy the gamepass or whatevr

1 comment

0

Yes, but will this also reward player points?

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