if PaymentType == "Robux" then
local GamePassId = Item.Info.PaymentInfo.GamePassId.Value
MarketplaceService:PromptGamePassPurchase(Player, GamePassId)
local playerwhoPurchased, Id, Purchased = MarketplaceService.PromptGamePassPurchaseFinished:Wait()
if playerwhoPurchased == Player then
if Id == GamePassId then
if Purchased then
return true
else
return false
end
end
end
end
Heres what I got so far the problem with this is that someone else could buy the gamepass it would still fire and return false, is it possible to detect only if a certain player buys a certain gamepass
Just listen for the event on the server it will fire with all the arguments, and then hook it up to a function that processes the game pass purchase.
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(playerwhoPurchased, Id, Purchased)
--then you give the players what they should get if they purchased it
end)
Because this is a remote function the client side has to wait till the server checks if the gamepass was ourchased, if the item was purchased on the client ui it says Item purchased
if PaymentType == "Robux" then
local GamePassId = Item.Info.PaymentInfo.GamePassId.Value
MarketplaceService:PromptGamePassPurchase(Player, GamePassId)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, GamePassId,Purchased )
print("purchased")
end)
print "s"
end
Im pretty sure :Connect() doesnt yield a script thats why I told you I needed to use :Wait()
This happened when exactly after I was prompted s was printed
You can fire back the exact event when the purchase was finished
Client
RequestPurchase:FireServer(GamePassId);
RequestPurchase.OnClientEvent:Connect(function(completed)
if completed then
textLabel.Text = "Purchased"
end;
end)
Server
RequestPurchase.OnServerEvent:Connect(function(Plr, GamePassId)
MarketplaceService:PromptGamePassPurchase(Player, GamePassId);
end);
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Plr, Id, Purchased)
if Purchased then
RequestPurchase:FireClient(User, true);
else
RequestPurchase:FireClient(User, false);
end
end)
So basically I prompt the gamepass in the client wait till its finished and then fire a remote event to the server when the thing is purchased then the server gives the player the item?
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Plr, Id, Purchased)
--the id argument is the gamepass id
-- the purchased bool tells you if it was bought or not
--player argument is player that was prompted
end)
ReplicatedStorage.ShopEvents.CheckPrice.OnServerInvoke = function(Player, Item, Folder)
local WasExploiting = AntiExploitModule.CheckLeaderstats(Player)
if WasExploiting == false then
local Item = Shopitems[Folder][Item]
local PaymentType = Item.Info.PaymentInfo.PaymentType.Value
local Price = Item.Info.PaymentInfo.Price.Value
local DoesPlayerAlreadyHaveitem
if Player:WaitForChild("SwordsOwned"):FindFirstChild(Item) then
DoesPlayerAlreadyHaveitem = true
else
DoesPlayerAlreadyHaveitem = false
end
if DoesPlayerAlreadyHaveitem then
return "AlreadyOwned"
else
if PaymentType == "Points" then
if Player.leaderstats.Points.Value >= Price then
Player.leaderstats.Points.Value = Player.leaderstats.Points.Value - Price
local ItemOwnedTag = Instance.new("StringValue")
ItemOwnedTag.Value = Item
ItemOwnedTag.Name = Item
ItemOwnedTag.Parent = Player.SwordsOwned
return true
else
return false
end
end
end
if PaymentType == "Robux" then
local GamePassId = Item.Info.PaymentInfo.GamePassId.Value
MarketplaceService:PromptGamePassPurchase(Player, GamePassId)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, GamePassId,Purchased )
print("purchased")
end)
print "s"
end
elseif WasExploiting == true then
local ThingtoSend = {
["content"] = Player.Name .. " tried to change his leaderstats value! CAUGH (doesnt really matter it doesnt replicate to the server)"
}
ThingtoSend = HttpService:JSONEncode(ThingtoSend)
HttpService:PostAsync(WebHook, ThingtoSend)
return false
end
You should prompt the game pass on the client. Have a listener on the server waiting for a purchase. If a purchase comes send a remote event back to the player telling them to update their UI. You also give the player their reward on the server.