--LocalScript inside button
local buyButton = script.Parent
local productId = 20518668
buyButton.MouseButton1Click:connect(function()
game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)
end)
local MarketplaceService = Game:GetService("MarketplaceService")
local ds = game:GetService("DataStoreService"):GetDataStore("PurchaseHistory")
local productId = 20518668
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 Item = game.ReplicatedStorage.Swords.Sword
Item:Clone().Parent = player.Backpack
Item:Clone().Parent = player.StarterGear
end
end
end
local playerProductKey = "player_" .. receiptInfo.PlayerId .. "_purchase_" .. receiptInfo.PurchaseId
ds:IncrementAsync(playerProductKey, 1)
return Enum.ProductPurchaseDecision.PurchaseGranted
end
I want this set so once a player buys a dev product they get a sword in their inv. Please help.

22 comments
I want to know if this works. If it didn't, I will edit this, otherwise you can let me know if it did.
localscript in button?
Yes
Ok it sorta works, it gives sword, but when the player leaves and rejoins they dont have the sword
either I want their swords with them forever and then they cant purchase pass again, or else, i can leave it there and just make them buy the pass whenever they want a sword
Ok I will try to do that
ok cool, thanks, its just i would prefer people to buy the pass once and they keep the item forever instead of when they leave they have to buy the poduct again. If you cant then I can live with it for now, but if you can try then thank you :)
I edited in a new block of code. It will give the player the sword if they bought the DP. Tell me if it works or not,k?
so everything is the exact same but the last which is new code?
Yes
dosent work, i think it has something to with new script. It gives sword on purchase, but dosent save
Ok Ill try to fix that
I think I fixed the mistake
Works, had to change some stuff but it works :D thanks +1 and answer accepted :D
Yay! 1 thing: can you tell me what you changed?
ok, in the one that checks if the player has brought thing then give it back tot them, it says player.Backpack, but should be Player.Backpack
Oh ok. The reason why it was lowercase "p" is because I copied it and did not check what has been pasted. I'm going to edit the answer so anyone else using the code won't have errors
yeah, i didnt need to test, and I knew that yo had copy and pasted :P oh and does it need to have Local Players = game.Players, cause you never used Players in the code
The reason why I added that is because I needed to use the PlayerAdded event, but I was so stupid I forgot to add the connection line, and when you told me it wasn't working I saw the mistake and fixed it.
it dosent work when you have multiple swords ?? ony 1 works, the others dont give the swords
You mean more than one sword? Ok I'll edit it so it gives more than one sword
Actually I am not sure how to do it