Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Developer product and Data Store script not working

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

2 comments

0

Can you use Roblox's Remote Error Monitor to find the error ingame?

0

Do you have a "GetPlayerById" function?

1 answer

✓ Accepted answer

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.")

1 comment

0

Thank you, God. Is there any way to test for these errors apart from reading through the script?

This discussion is preserved as it was. New answers, comments, and votes are closed.