Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How do I give out swords after purchasing a dev product?

Asked by 10 years ago

I've tried multiple ways to get a sword after I buy a dev product but non of them work!!! Can someone make a script for me? Thx!!!

1 answer

Log in to vote
1
Answered by
2eggnog 981 Moderation Voter
10 years ago

When you want to prompt the purchase of a developer product, run this (replacing the player with path to the player and productid with the ID of the product.)

game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)

Then put this in a script to actually give out the swords.

local devId = 0 --Put the dev product ID here
local sword = game:GetService("ServerStorage"):FindFirstChild("Sword") --Put the path to the sword here

game:GetService("MarketplaceService").ProcessReceipt = function(receiptInfo)
    for i,v in ipairs (game.Players:GetChildren()) do
        if v.userId == receiptInfo.PlayerId then --If the player matches the player in the receipt
            if receiptInfo.ProductId == devId then --If it's the correct developer product
                if pcall(function()
                sword:Clone().Parent = v.StarterGear
                sword:Clone().Parent = v.Backpack
                end) then return Enum.ProductPurchaseDecision.PurchaseGranted end --Tells the marketplace service that purchase went smoothly.
            end
        end
    end
end
0
What do u mean "put the path to the sword here" Newomri 0 — 10y
0
Well, if the sword is located in the Lighting, the path would be game.Lighting.Sword. If the sword were located in the server storage, it would be game.ServerStorage.Sword. 2eggnog 981 — 10y
0
I know that but how will I add it to the script? Plus I want to make the sword an illumina Newomri 0 — 10y
0
Set the value of the sword variable to the sword. Simple as that. If you don't understand, I recommend visiting the wiki to learn about object hierarchy. 2eggnog 981 — 10y
Ad

Answer this question