Hello, I’m wondering how should I process a purchase on the server with this local script structure.
for _, imageLabel in pairs(WeaponsListFrame:GetChildren()) do
local button = imageLabel:FindFirstChildWhichIsA("TextButton")
if button then
local buttonType = button:GetAttribute("Type")
local btnName = button.Name
if buttonType == "Coins" then
button.MouseButton1Click:Connect(function()
shopEvent:FireServer(btnName)
end)
elseif buttonType == "Robux" then
button.MouseButton1Click:Connect(function()
local gamepassId = ShopConfig[btnName].gamepassId
MarketPlaceService:PromptGamePassPurchase(player, gamepassId)
print(gamepassId)
end)
end
end
end
When I had single gamepass I used this on server
local gamepassId = 1391743106
Players.PlayerAdded:Connect(function(player)
local hasGamepass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId)
if hasGamepass then
print(player.Name .. "Has gamepass with id" .. gamepassId)
end
end)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, id, purchaseSuccessful)
if purchaseSuccessful and id == gamepassId then
print(player.Name .. "Has bought gamepass" .. id)
end
end)
Just check if a user owns each gamepass individually and then also check if they bought it. Doesn’t seem like you’re experiencing and issue really. They way you would change it on the server depends on your game
Players.PlayerAdded:Connect(function(player)
local hasGamepass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamepassId)
if hasGamepass then
print(player.Name .. "Has gamepass with id" .. gamepassId)
end
end)
Good. On the server, require the module and then do something like
local ShopConfig = require(path.to.module)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, id, purchaseSuccessful)
if not purchaseSuccessful then return end
local pass = nil
for _, item in pairs(ShopConfig) do
if item.gamepassId == id then
pass = item
break
end
end
if not pass then warn("Couldn't process gamepass purchase") return end
print(`Player {player.Name} bought gamepass with id: {item.gamepassId} ({item.TypeOfPrice})`)
end)