when player want to pay the game pass he will pay it
but the player need to leave and join (to the game pass work)
the script
local gamepass = Instance.new("IntValue")
gamepass.Parent = lod
gamepass.Name = "x2coins"
gamepass.Value = 1
if markplaceserver:UserOwnsGamePassAsync(player.UserId,coins2xid) then
gamepass.Value = 2
end
From the looks of it, it seems as if you are checking if the player has the gamepass once and then never again. What I recommend you do is that you set up a listener to update the value if the player buys the gamepass. You can do that by utilizing the PromptGamePassPurchaseFinished event.
If you plan on checking on the client, then use the UserOwnsGamePassAsync like you did here, but make sure you call it each time you want to check.
If you want more information on gamepasses, I highly recommend you check out the Game Passes article on the Roblox Creator Documentation. You can find it here.
when i search about "PromptGamePassPurchaseFinished" i dont find any thing help me in my issue with game pass
why (bc i dont know where should for me to type āPromptGamePassPurchaseFinishedā)
i have this script
local mps = game:GetService("MarketplaceService")
local id = 97272435
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Click:Connect(function()
mps:PromptGamePassPurchase(player,id)
end)
with this script
if markplaceserver:UserOwnsGamePassAsync(player.UserId,coins2xid) then
gamepass.Value = 2
end
and only i need some help to know
where should for me to type āPromptGamePassPurchaseFinishedā function
iām newbie in game pass scripts for that its hard for me);
I am currently from my phone, so Iām unable to present you with a code example, but the problem is that PromptGamePassPurchaseFinished is an event, not a function. It should be used as such:
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(player, gamepassId, purchaseSuccessful)
-- Do stuff here
end)
I highly recommend you look at the code examples on the Creator Documentation if you have any further issues.
local marketPlaceService = game:GetService("MarketPlaceService")
local gamepassID = -- gamepass ID
marketPlaceService.PromptGamePassPurchaseFinished:Connect(function(player, purchasePassID, purchaseSuccess)
if purchaseSuccess == true and purchasePassID == gamepassID then
print(player.Name.. " purchased the gamepass")
end
end)
I went ahead and made an demo that basically achieves what you want. Keep in mind, this is a demo. You should make your code more āsafeā by adding more checks, such as in the gamepass function. Hopefully this demo will help you understand:
-- Services --
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
-- Tables --
local GamepassFunctions = {
[101409980] = function(Player, GamepassId, WasPurchased)
if WasPurchased then
print(Player.Name.." purchased gamepass with ID "..GamepassId..". Purchase successful? "..tostring(WasPurchased))
Player.PlayerInfo.x2Coins.Value = 2
end
end,
}
-- Scripting --
Players.PlayerAdded:Connect(function(Player)
local PlayerInfo = Instance.new("Folder", Player)
PlayerInfo.Name = "PlayerInfo"
local Gamepass = Instance.new("IntValue", PlayerInfo)
Gamepass.Name = "x2Coins"
Gamepass.Value = 1
if MarketplaceService:UserOwnsGamePassAsync(Player.UserId, 101409980) then
Gamepass.Value = 2
end
end)
MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Player, GamepassId, WasPurchased)
if WasPurchased then
if GamepassFunctions[GamepassId] then
GamepassFunctions[GamepassId](Player, GamepassId, WasPurchased)
end
end
end)