This article on the DevHub by Roblox should help you out. Scroll down a bit and it will show you how to use the MarketPlaceService for prompting gamepass purchases.
It says there, " This code can be placed in a LocalScript and the promptPurchase() function can be called when the player presses a button, when their character touches a part, or whatever fits your game design."