So I’m trying to make devproducts where the player can buy it for money. The client-side script I have seems to be printing out fine. The issue I have is with the server script. I have no errors in the output and there just isn’t a prompt coming up for me when I tested in studio. It’s kind of late so maybe I’m just tired and missing something obvious, but any help is appreciated
local productIds = {
["Button1"] = "1576870616",
["Button2"] = "1576870960",
["Button3"] = "1576871506",
}
local moneyAmounts = {
["Button1"] = 1000,
["Button2"] = 5000,
["Button3"] = 10000,
}
promptPurchase.OnServerEvent:Connect(function(player, productId)
local productPrice = productIds[productId]
if not productPrice then
return
end
game:GetService("MarketplaceService"):PromptProductPurchase(player, productPrice)
local playerData = data[player.UserId]
if playerData then
local moneyAmount = moneyAmounts[productId]
if moneyAmount then
playerData.Money += moneyAmount
updateMoney:FireClient(player, playerData.Money)
end
end
end)
There’s 3 different devproducts with 3 different buttons on the gui I have by the way that’s why I made it like that
I don’t know how the localscript looks like, so maybe this isn’t the case, but I’m guessing you are maybe sending the wrong arguments in the remoteevent. That would be the only case in your code when nothing would happen.
Or maybe it’s just a studio thing, but that would probably show an error message then.
Well here’s the localscript inside of each of the buttons:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local promptPurchase = ReplicatedStorage:WaitForChild("PromptPurchase")
local button = script.Parent
button.MouseButton1Click:Connect(function()
print("working")
local productId = "1576870616"
promptPurchase:FireServer(productId)
end)
local productIds = {
["Button1"] = 1576870616,
["Button2"] = 1576870960,
["Button3"] = 1576871506,
}
local moneyAmounts = {
[1576870616] = 1000,
[1576870960] = 5000,
[1576871506] = 10000,
}
promptPurchase.OnServerEvent:Connect(function(player, productId)
local productPrice = productIds[productId]
if not productPrice then
return
end
game:GetService("MarketplaceService"):PromptProductPurchase(player, productPrice)
local playerData = data[player.UserId]
if playerData then
local moneyAmount = moneyAmounts[productPrice]
if moneyAmount then
playerData.Money = playerData.Money + moneyAmount
updateMoney:FireClient(player, playerData.Money)
end
end
end)
Only problem being, there is no key in the dictionary which is the product ID(the key is the first value in case you didn’t know)
To fix this I suggest you write your server code like this:
local productIds = {
[1576870616] = 1000,
[1576870960] = 5000,
[1576871506] = 10000,
}
promptPurchase.OnServerEvent:Connect(function(player, productId)
local productPrice = productIds[productId]
if not productPrice then
return
end
game:GetService("MarketplaceService"):PromptProductPurchase(player, productId)
local playerData = data[player.UserId]
if playerData then
playerData.Money = playerData.Money + productPrice
updateMoney:FireClient(player, playerData.Money)
end
end)
There is still a fatal mistake however: You never actually check the result of the transaction, so the user might as well have cancelled the request and never paid, but still gotten the reward. I’m not sure how to properly use dev products so you have to find out yourself.