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

How do I make so a script only executes if a certain developer product is bought?

Asked by 1 year ago

Here is the script I want to be executed:

wait(1)

script.Parent.Missle.Base.Anchored = true

debounce = false

script.Parent.Button.ClickDetector.MouseClick:connect(function()
    if debounce == false then
        debounce = true
        script.Parent.Button.Sound:Play()

        local siren = script.Parent.Button.Siren
        siren.Parent = workspace
        siren:Play()

        coroutine.resume(coroutine.create(function()
            local lights = script.Parent.Lights:GetChildren()
            for i=1,100 do
                for i,v in pairs(lights) do
                    v.SpotLight.Enabled = true
                end
                wait(0.54)
                for i,v in pairs(lights) do
                    v.SpotLight.Enabled = false
                end
                wait(0.54)          
            end
        end))

        wait(2)

        script.Parent.Missle.Base.Fire.Enabled = true
        script.Parent.Missle.Base.Smoke.Enabled = true

        wait(3)

        script.Parent.Missle.PrimaryPart = script.Parent.Missle.Base    
        for i=1,320 do
            script.Parent.Missle:SetPrimaryPartCFrame(script.Parent.Missle:GetPrimaryPartCFrame()+Vector3.new(0,0.05*((1.1^(i/5))/3),0))
            wait()
        end
        wait()
        for i=1,100 do
            script.Parent.Missle:SetPrimaryPartCFrame(script.Parent.Missle:GetPrimaryPartCFrame()+Vector3.new(0,0.05*(1.1^((250-i)/5)/3),0))
                script.Parent.Missle:SetPrimaryPartCFrame(script.Parent.Missle:GetPrimaryPartCFrame()*CFrame.Angles(0,math.pi/100,0))
                script.Parent.Missle:SetPrimaryPartCFrame(script.Parent.Missle:GetPrimaryPartCFrame()+Vector3.new(0,0,-i/100))  
            wait()
        end
        wait()
        for i=200,120,-1 do
            script.Parent.Missle:SetPrimaryPartCFrame(script.Parent.Missle:GetPrimaryPartCFrame()-Vector3.new(0,0.1*((1.1^(i/2.95))/4),0))
            wait()
        end 

        script.Parent.Missle.Tip.Transparency = 0.5
        script.Parent.Missle.Tip.CanCollide = false
        script.Parent.Missle.Tip.Mesh.Scale = Vector3.new(1,1,1)
        local boom = script.Parent.Button.Boom
        boom.Parent=workspace
        boom:Play()
        local frame = script.Parent.Missle.Tip.CFrame

        script.Parent.Missle.Tip.Boom.Disabled = false  

        for i=1,400 do
            script.Parent.Missle.Tip.Size=script.Parent.Missle.Tip.Size+Vector3.new(3,3,3)
            script.Parent.Missle.Tip.CFrame=frame
            wait()
        end
        script.Parent.Missle.Tip.Boom.Disabled=true
        script.Parent.Missle:Destroy()
        siren:Stop()
        boom:Stop()


    end
end)

1 answer

Log in to vote
0
Answered by 1 year ago

You can do this by listening to the receipts being processed by the MarketPlaceService and checking if the purchase went well.

For example:

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local ProductId = 000000000 -- Your Developer Product Id

local function Bought(Receipt)
    -- Your code here

    return true -- Indicate a successful purchase
end

local function CheckReceipt(ReceiptInfo)
    local Player = Players:GetPlayerByUserId(ReceiptInfo.UserId, ReceiptInfo)
    if Player then -- For security purposes
        if not ReceiptInfo.ProductId == ProductId then
            return -- Cancel the function early if it isn't the product you're listening for
        end

        local success, result = pcall(Bought)
        if success then
            return Enum.ProductPurchaseDecision.PurchaseGranted
        else
            warn("Failed to process receipt:", receiptInfo, result)
        end
    end

    return Enum.ProductPurchaseDecision.NotProcessedYet
end

MarketplaceService.ProcessReceipt = processReceipt

Note that I actually do not know if this script works as it should since I couldn't test it, please tell me if you have any issues with the script.

Ad

Answer this question