I’ve made a simple script to reward the player with a certain amount of gemstones after purchasing a developer product, but It’s missfunctioning. Its always adding itself up, which it obviously is not supposed to do. I searched up solutions which helped for others but didnt help me. Attached Video Clip:
Script:
local mps = game:GetService("MarketplaceService")
local notifyModule = require(game:GetService("ReplicatedStorage"):WaitForChild("Modules"):WaitForChild("NotifyUser"))
local GEMS_15K = 1348103834
local GEMS_50K = 1348103909
local GEMS_125K = 1348104005
local GEMS_500K = 1348104207
local devProducts = {
gems_15k = {
name = "+15,000 Gems!",
id = GEMS_15K,
price = 59,
func = function(plr)
plr.ValueFolder.Gemstones.Value += 15000
notifyModule.notify(plr, "Thank you so much for supporting my game!", Color3.new(1, 0.333333, 0.498039))
end,
},
gems_50k = {
name = "+50,000 Gems!",
id = GEMS_50K,
price = 129,
func = function(plr)
plr.ValueFolder.Gemstones.Value += 50000
notifyModule.notify(plr, "Thank you so much for supporting my game!", Color3.new(1, 0.333333, 0.498039))
end,
},
gems_125k = {
name = "+125,000 Gems!",
id = GEMS_125K,
price = 279,
func = function(plr)
plr.ValueFolder.Gemstones.Value += 125000
notifyModule.notify(plr, "Thank you so much for supporting my game!", Color3.new(1, 0.333333, 0.498039))
end,
},
gems_500k = {
name = "+500,000 Gems!",
id = GEMS_500K,
price = 599,
func = function(plr)
plr.ValueFolder.Gemstones.Value += 500000
notifyModule.notify(plr, "Thank you so much for supporting my game!", Color3.new(1, 0.333333, 0.498039))
end,
}
}
function mps.ProcessReceipt(receipt)
local devProductId = receipt.ProductId
local plr = game:GetService("Players"):GetPlayerByUserId(receipt.PlayerId)
for i, product in pairs(devProducts) do
if product.id == devProductId then
local s, e = pcall(function()
product.func(plr)
return Enum.ProductPurchaseDecision.PurchaseGranted
end)
end
end
end