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

MarketPlaceService + Data Store script not functioning 100%

Asked by
TomsGames 225 Moderation Voter
10 years ago

In the startpack I have a localscript with this:

local productId = 19186931
plr = game.Players.LocalPlayer
plrgui = plr:WaitForChild("PlayerGui")

plrgui.ChildAdded:connect(function(child)
if child.Name == "EndGui" then
    wait()
    buyButton = script.Parent.Parent.PlayerGui.EndGui.Continue
    buyButton.MouseButton1Click:connect(function()
    if buyButton.Visible == true then
    Game:GetService("MarketplaceService"):PromptProductPurchase(game.Players.LocalPlayer, productId)
    end
end)
    end
end)

This script seemingly works perfectly. It fires the transaction, so that's all good! It's the server side script in Workspace that seems to have problems.

This is the server script:

local MarketplaceService = Game:GetService("MarketplaceService")
local productId = 19186931
local ds = game:GetService("DataStoreService"):GetDataStore("ContinueButton")

function GetPlayerById(id)
    for _,v in ipairs(game.Players:GetPlayers())do
        if(v.userId==id)then
        return(v) 
        end
    end
    return(nil)
end

MarketplaceService.ProcessReceipt = function(receiptInfo)
    if receiptInfo.ProductId == productId then
    local asynccode = receiptInfo.PlayerId .. "buys"
        if ds:GetAsync(asynccode) == nil then
            ds:SetAsync(asynccode, 0) 
        end
    ds:IncrementAsync(asynccode, 1)
    print("Player bought the continue developer product. Player now has "..ds:GetAsync(asynccode).." buys.")

    currentplr = GetPlayerById(receiptInfo.PlayerId)

    gui = currentplr.PlayerGui
    gui.continuegame.Disabled = false

    return Enum.ProductPurchaseDecision.PurchaseGranted     
    end
    end

I have tried using both ROBLOX remote error and Obox checking system but neither print any of the prints I have and neither display any errors.. But it doesn't work!

What's wrong? If you can offer a solution to the debugger that'd be even better!

1 answer

Log in to vote
0
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

(P.S. you could have edited the old question rather than make a new one)

Try changing line 17 in the Script to this:

if not (ds:GetAsync(asynccode) or false) then 

If that doesn't work, try using a RemoteFunction to call the PromptProductPurchase from the Script instead of the LocalScript.

1
That line checks to make sure it DOESN'T exist, right? TomsGames 225 — 10y
0
Actually, now that you mention it, no. Let me fix that real quick. adark 5487 — 10y
0
There, try it now. adark 5487 — 10y
1
"print((function() end)() == nil)" > true. He can compare ds:GetAsync(asynccode) to nil and it'll work. User#2 0 — 10y
View all comments (2 more)
0
InspiredArbitrator you should marry me <3 TomsGames 225 — 10y
0
Wierd. Last time I tried to do that it didn't work. adark 5487 — 10y
Ad

Answer this question