I have a script that processes purchases of a Developer Product, and then fires RemoteEvents for each purchase to the client to send a little notification to the player telling them a certain amount of currency has been added (dependent on purchase).
The issue I’m having is that when a product is purchase the first time, it works as expected. From there though, each time you purchase a product it will not only fire for the product you bought, but also for every single product you bought in that same playing session. The notification shows for the player, but isn’t actually saved to the datastore. As for the UI displaying the coin amount, it sometimes will set to the incorrect amount, but then after a brief moment it will fix itself. Not really sure what’s happening… I would appreciate some help!
Server Code:
if recieptInfo.ProductId == 1799122150 then -- 50 coins
local success, rcdata = pcall(function()
return cStore:GetAsync(plr.UserId)
end)
local updatedcoins = rcdata + 50
cStore:SetAsync(plr.UserId, updatedcoins)
local amtadd = 50
EventsFolder.CoinData:FireClient(plr, updatedcoins)
EventsFolder.PingCoins:FireClient(plr, amtadd)
print("pinged client for "..amtadd.." coins")
return
end
if recieptInfo.ProductId == 1799123110 then -- 250 coins
local success, rcdata = pcall(function()
return cStore:GetAsync(plr.UserId)
end)
local updatedcoins = rcdata + 250
cStore:SetAsync(plr.UserId, updatedcoins)
local amtadd = 250
EventsFolder.CoinData:FireClient(plr, updatedcoins)
EventsFolder.PingCoins:FireClient(plr, amtadd)
print("pinged client for "..amtadd.." coins")
return
end
if recieptInfo.ProductId == 1799128785 then -- 500 coins
local success, rcdata = pcall(function()
return cStore:GetAsync(plr.UserId)
end)
local updatedcoins = rcdata + 500
cStore:SetAsync(plr.UserId, updatedcoins)
local amtadd = 500
EventsFolder.CoinData:FireClient(plr, updatedcoins)
EventsFolder.PingCoins:FireClient(plr, amtadd)
print("pinged client for "..amtadd.." coins")
return
end
if recieptInfo.ProductId == 1799129255 then -- 1000 coins
local success, rcdata = pcall(function()
return cStore:GetAsync(plr.UserId)
end)
local updatedcoins = rcdata + 1000
cStore:SetAsync(plr.UserId, updatedcoins)
local amtadd = 1000
EventsFolder.CoinData:FireClient(plr, updatedcoins)
EventsFolder.PingCoins:FireClient(plr, amtadd)
print("pinged client for "..amtadd.." coins")
return
end
Client Code:
game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents").CoinData.OnClientEvent:Connect(function(cdata)
print("cdata recieved of "..cdata.." coins")
coins:setLabel(cdata)
print("cdata of "..cdata.." coins has been set")
end)
game:GetService("ReplicatedStorage"):WaitForChild("RemoteEvents").PingCoins.OnClientEvent:Connect(function(amtadd)
print("ping recieved for "..amtadd.." coins")
StarterGui:SetCore("SendNotification", {
Title = "+"..amtadd.." Coins",
Text = amtadd.." coins have been added to your balance!",
Icon = "rbxassetid://16976008884"
})
end)```