-
What do you want to achieve?
I want to save a data to datastore once the purchase is done - developer product -
What is the issue? Include screenshots / videos if possible!
It wont save the data to datastore once purchase. Only the cancel print works. Other functions works perfectly but once I made the PromptProductPurchaseFinished, it wont save anymore to datastore. -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Change variable and remove other funcitons.
local function onConfirmGiftButtonClick()
Sound:Play()
local giftFrame = script.Parent.Parent.Parent:FindFirstChild("SelectGi").Main
local usernameBox = giftFrame:FindFirstChild("InputName")
if usernameBox and usernameBox.Text ~= "" then
recipientName = usernameBox.Text
loadRecipientAvatar(recipientName)
local success, recipientUserId = pcall(function()
return Players:GetUserIdFromNameAsync(recipientName)
end)
if success and recipientUserId then
local gifterName = Players.LocalPlayer.Name
if selectedGamePass and not checkIfUserHasProduct(Players:GetPlayerByUserId(recipientUserId), selectedGamePass) then
MarketplaceService:PromptProductPurchase(Players.LocalPlayer, selectedGamePass, recipientUserId)
else
print("mali walang product o meron na")
end
else
print("walang player or mali")
end
else
print("mali")
end
end
MarketplaceService.Prompt:Connect(function(player, gamePassId, wasPurchased)
if wasPurchased and player == Players.LocalPlayer and gamePassId == selectedGamePass then
local gifterName = Players.LocalPlayer.Name
GiftRemote:FireServer(recipientName, selectedGamePass, gifterName)
announceGift(gifterName, recipientName, selectedGamePassName)
print("bought")
else
print("didnt")
end
end)
ServerScriptService:
local DataStoreService = game:GetService("DataStoreService")
local Players = game:GetService("Players")
local giftDataStore = DataStoreService:GetDataStore("GiftDataStore")
local GiftRemote = game.ReplicatedStorage:WaitForChild("GiftRemote")
local gamePassNames = {
[1938014118] = "VIP",
[914470385] = "Avatar Size Editor",
[914519126] = "10x LVL Boost",
[914014133] = "2x LVL Boost"
}
GiftRemote.OnServerEvent:Connect(function(player, recipientName, productId, gifterName)
local recipient = nil
for _, p in ipairs(Players:GetPlayers()) do
if p.Name:lower() == recipientName:lower() then
recipient = p
break
end
end
local giftKey = recipientName .. "_gift_" .. productId
local success, errorMsg = pcall(function()
giftDataStore:SetAsync(giftKey, {
Gifter = gifterName,
Recipient = recipientName,
ProductId = productId,
})
end)
if not success then
warn("Error saving gift data: " .. errorMsg)
else
print("Gift recorded: " .. giftKey)
end
end)
I appreciate your help. Thank you!