I have looked all over and nowhere have I found a solution, I even tried just copy and pasting from the new wiki site and altering the gamepass ID. I tried changing the ID ot the full link. I have no idea where to go from here. Reading the new way to handle gamepasses on the devforum does not address this anywhere though? The ID is always leading me to an asset not the gamepass.
-- This code should be within a 'LocalScript' object local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local gamePassID = 5327756 -- Change this to your game pass ID -- Function to prompt purchase of the game pass local function promptPurchase() local player = Players.LocalPlayer local hasPass = false local success, message = pcall(function() hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID) end) if not success then warn("Error while checking if player has pass: " .. tostring(message)) return end if hasPass == true then -- Player already owns the game pass; tell them somehow else -- Player does NOT own the game pass; prompt them to purchase MarketplaceService:PromptGamePassPurchase(player, gamePassID) end end
Anyone know why?
AFAIK, the code is well written, without any errors.. Actually, I think I've seen it before, I believe that's in a template. So, first of all, I advice you to check to see if that gamepass ID actually exists, and it is one that you created (5327756).
Assuming you did, you turned the code into a function, but never called it. So:
We can make it run the function:
-- This code should be within a 'LocalScript' object local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local gamePassID = 5327756 -- Change this to your game pass ID -- Function to prompt purchase of the game pass local function promptPurchase() local player = Players.LocalPlayer local hasPass = false local success, message = pcall(function() hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID) end) if not success then warn("Error while checking if player has pass: " .. tostring(message)) return end if hasPass == true then -- Player already owns the game pass; tell them somehow else -- Player does NOT own the game pass; prompt them to purchase MarketplaceService:PromptGamePassPurchase(player, gamePassID) end end -- Run the function promptPurchase()
or make it actual running code, or by other words, remove the function indication:
-- This code should be within a 'LocalScript' object local MarketplaceService = game:GetService("MarketplaceService") local Players = game:GetService("Players") local gamePassID = 5327756 -- Change this to your game pass ID -- Make this not be a function, so it will run. local player = Players.LocalPlayer local hasPass = false local success, message = pcall(function() hasPass = MarketplaceService:UserOwnsGamePassAsync(player.UserId, gamePassID) end) if not success then warn("Error while checking if player has pass: " .. tostring(message)) return end if hasPass == true then -- Player already owns the game pass; tell them somehow else -- Player does NOT own the game pass; prompt them to purchase MarketplaceService:PromptGamePassPurchase(player, gamePassID) end
If it works, please mark this as the correct answer. :P