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

How do you make an on touch script and then a robux payment tip comes up?

Asked by 7 years ago

I have been trying to get a script with a Developer Product ID that would make a robux payment tip screen to pop up. I can't seem to be able to find one that works. -Probably that I am bad at scripting-. But it would be helpful of someone to find a script and direct me to what I should do. I know about Developer Products and I have one ready - 87872498 - but i can't find out how to do it or how it works.

2 answers

Log in to vote
1
Answered by 7 years ago
Edited 7 years ago

Here is a rather simpler answer. Put this in the part (Normal Script):

local id = 87872498 --Your id 
local MarketPlaceService = game:GetService("MarketplaceService")

script.Parent.Touched:connect(function(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
MarketPlaceService:PromptPurchase(player,id)
end)

Use the ReceipProcessor I took from the Roblox Wiki and put it in the ServerScriptService in a normal script:

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

local Products = {
            [87872498] = function(receipt,player)
        local stats = player:findFirstChild("leaderstats")
        local gold = stats and stats:findFirstChild("YourStatName") --Put your currency name here
        if not gold then return end
        gold.Value = gold.Value + 500 --put how much you want to reward here
        return true 
    end;
}
 --TAKEN FROM ROBLOX WIKI
function MarketplaceService.ProcessReceipt(receiptInfo) 
    local playerProductKey = receiptInfo.PlayerId .. ":" .. receiptInfo.PurchaseId
    if PurchaseHistory:GetAsync(playerProductKey) then
        return Enum.ProductPurchaseDecision.PurchaseGranted --We already granted it.
    end
    -- find the player based on the PlayerId in receiptInfo
    local player,handler -- handler is used a few lines lower
    for k,v in ipairs(game:GetService("Players"):GetPlayers()) do
        if v.userId == receiptInfo.PlayerId then
            player = v break -- we found him, no need to search further
        end 
    end

    -- player left? not sure if it can happen, but to be sure, don't process it
    if not player then return Enum.ProductPurchaseDecision.NotProcessedYet end

    for productId,func in pairs(Products) do
        if productId == receiptInfo.ProductId then
            handler = func break -- found our handler
        end
    end

    -- apparently it's not our responsibility to handle this purchase
    -- if this happens, you should probably check your productIds etc
    -- let's just assume this is ment behavior, and let the purchase go through
    if not handler then return Enum.ProductPurchaseDecision.PurchaseGranted end

    -- call it safely with pcall, to catch any error
    local suc,err = pcall(handler,receiptInfo,player)
    if not suc then
        warn("An error occured while processing a product purchase")
        print("\t ProductId:",receiptInfo.ProductId,"\n","Player:",player)
        print("\t Error message:",err) -- log it to the output
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    -- if the function didn't error, 'err' will be whatever the function returned
    -- if our handler didn't return anything (or it returned false/nil), it means
    -- that the purchase failed for some reason, so we have to cancel it
    if not err then
        return Enum.ProductPurchaseDecision.NotProcessedYet
    end

    -- record the transaction in a Data Store
    suc,err = pcall(function()
        PurchaseHistory:SetAsync(playerProductKey, true)
    end)
    if not suc then
        print("An error occured while saving a product purchase")
        print("\t ProductId:",receiptInfo.ProductId,"\n","Player:",player)
        print("\t Error message:",err) -- log it to the output
        print("\t Handler worked fine", "purchase granted") -- add a small note that the actual purchase has succeed
    end
    -- tell ROBLOX that we have successfully handled the transaction (required)
    return Enum.ProductPurchaseDecision.PurchaseGranted     
end

If this doesn't work please comment. If it did, upvote and accept answer.

0
Heay PyccknnXakep um the screen for the transaction does popup but it says that the product is not for sale and you can't buy it. 10TheDragon10 7 — 7y
0
You probably need to change the ID's or make a new developer product. Make sure the product is in the place you are editing. PyccknnXakep 1225 — 7y
Ad
Log in to vote
-2
Answered by 7 years ago
Edited 7 years ago

{In the part you want the player to touch!}

Make a script in the part you wanna touch to open and say this in the script...

I am sorry I didn't have time to test the script, and the previous script I was exhausted so sorry.

script.Parent.Touched:Connect(function(onTouched)
    game.Players.LocalPlayer.PlayerGui.GUINAME.Enabled = true
end)

or if your doing a frame visible do...

script.Parent.Touched:Connect(function(onTouched)
    game.Players.LocalPlayer.PlayerGui.GUINAME.Frame.Visible = true
end)

{In the GUI}

Make a GUI saying this and disable the GUI in the GUI's property or make the frame not visible.

local plr = script.Parent.Parent.Parent.Parent.Parent --this or game.Players.LocalPlayer
local link = game:GetService("MarketplaceService") --REALLY IMPORTANT
deb = 0


script.Parent.MouseButton1Click:connect(function()
local marketId = script.Name --ID OF YOUR DEVELOPER PRODUCT  
link:PromptProductPurchase(plr,marketId) --IMPORTANT
link.ProcessReceipt = function(receiptInfo) --IMPORTANT
if Enum.ProductPurchaseDecision.PurchaseGranted and receiptInfo.PlayerId == plr.userId  --IMPORTANT
then
if deb == 0 then
deb = 1
plr.leaderstats.CURRENCYNAME.Value = plr.leaderstats.CURRENCYNAME.Value + 500 --Alter what stat you would like to increase or decrease after the player has purchased.
wait(1)
deb = 0
end
end
end
end)
1
> touch Goulstem 8144 — 7y
0
Heay Goldenkings11 im not sure where to put the productID I know you put it in the spot you told me to but it appears to be doing nothing when you touch the part. I don't know how to put the productID in the spot you told me in the script. 10TheDragon10 7 — 7y

Answer this question