I'll explain the code first.
The client sends a remote event to the server containing the string value for an ImageID and another string value called CustomType. The server will prompt a different product mattering on the CustomType.
RemoteEvents.C2S.Gamepass.CustomId.OnServerEvent:Connect(function(Player,ImageId,CustomType)
local ProductId
if CustomType == "Emote" then
ProductId = GamepassFolder.CustomIds.CustomEmote.ProductId.Value
elseif CustomType == "BannerIcon" then
ProductId = ReplicatedStorage.Gamepasses.CustomIds.CustomBannerIcon.ProductId.Valuee
end
if ProductId ~= nil then--If ProductId isn't an empty value
MarketplaceService:PromptProductPurchase(Player,ProductId)
else
print("Product id was nil")
end
MarketplaceService.ProcessReceipt = ProcessReceipt(ImageId)--Does function for when the player buys any of the products
end)
This is the function that will run when the player clicks the buy button, which is also MarketplaceService.ProcessReceipt = ProcessReceipt(ImageId) from the remote event.
Mattering on the product id, a Player's value stored inside them will be change to the ImageId string.
Problem is that it tells me 1 argument is missing or nil, which I don't quite really understand.
function ProcessReceipt(ReceiptInfo, ImageId)
local Player = Players:GetPlayerByUserId(ReceiptInfo.PlayerId)
if Player then
if ReceiptInfo.ProductId == ReplicatedStorage.Gamepasses.CustomIds.CustomEmote.ProductId.Value then
Player.Essentials.Equipped.Emotes.CustomEmote.Value = ImageId
print("Successfully changed Custom Emote")
elseif ReceiptInfo.ProductId == ReplicatedStorage.Gamepasses.CustomIds.CustomBannerIcon.ProductId.Value then
Player.Essentials.Equipped.Banner.CustomBannerIcon.Value = ImageId
print("Successfully changed Banner Icon")
end
return Enum.ProductPurchaseDecision.PurchaseGranted--Allows purchase
end
end
