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

Developer product and Data Store script not working

Asked by
TomsGames 225 Moderation Voter
10 years ago

So, this script. It is a server side script in the Workspace. I do not know how to debug test it as I am now allowed (apparently) in start server/player and play solo. Can't see the output of the script, I don't even know if it activates. But basically, click a gui and buy a gamepass (gamepass 19186931) so I assume that activates this function? So it SHOULD start.. But what's stopping it?

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

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
local numberBought = ds:IncrementAsync(asynccode, 1)
print("Player bought the continue developer product. Player now has "..GetAsync(asynccode) .. " buys.")

currentplr = GetPlayerById(receiptInfo.PlayerId)

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

return Enum.ProductPurchaseDecision.PurchaseGranted 
end
end

function GetPlayerById(id)
for _,v in ipairs(game.Players:GetPlayers())do
if(v.userId==id)then
return(v) 
end
end
return(nil)
end
0
Can you use Roblox's Remote Error Monitor to find the error ingame? FromLegoUniverse 264 — 10y
0
Do you have a "GetPlayerById" function? User#2 0 — 10y

1 answer

Log in to vote
1
Answered by
Merely 2122 Moderation Voter Community Moderator
10 years ago

You're calling GetPlayerById on line 14, but you didn't define the function until line 23. You're going to get the error "attempt to call global 'GetPlayerById' (a nil value)". You should move the GetPlayerId function before your function for handling purchases.

On line 12 you use GetAsync without supplying the instance you're calling it on. The fixed line should be:

print("Player bought the continue developer product. Player now has "..ds:GetAsync(asynccode) .. " buys.")
0
Thank you, God. Is there any way to test for these errors apart from reading through the script? TomsGames 225 — 10y
Ad

Answer this question