Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do I prompt game pass purchase only to users who haven't purchased yet?

Hey scriptinghelpers, just wondering how do I prompt a game pass purchase only to users who haven't purchased it yet? The code provided below is what I'm using, it work's even with the prompt purchase. I was wondering how I would prompt the game pass purchase only to users who have not purchased it yet? I have been referring to the MarketplaceService link https://developer.roblox.com/en-us/api-reference/class/MarketplaceService for help with this but, can't seem to find exactly what I'm looking for there so I thought I might as well ask for help. As I always say I'm only here to learn! Thank you for the help in advance, I appreciate it.

This is a Script inside of a Part inside of Workspace.

--did some editing
local debounce = true
local MarketplaceService = game:GetService("MarketplaceService")
local GamepassId = 17468467
script.Parent.Touched:Connect(function(hit)
	if debounce == true and hit.Parent:FindFirstChild("Humanoid") then
		local character = hit.Parent
		local player = game:GetService("Players"):GetPlayerFromCharacter(character)
		MarketplaceService:PromptGamePassPurchase(player, GamepassId)--where im prompting purchasing currently (prompts everyone on touch)
		if player and MarketplaceService:UserOwnsGamePassAsync(player.UserId, GamepassId) and player.leaderstats.Tix.Value >= 666 then
			debounce = false
			local avatar = character:GetChildren()
			for _,t in pairs(avatar) do
				if t.ClassName == "Part" then
					local fire = t.Fire
					fire.Color = Color3.new(1,0,0)
					fire.SecondaryColor = Color3.new(0,0,0)
--tried using else here, only worked if player already owned the game pass
				end
			end
		end
		wait(1)
		debounce = true
	end
end)
--let me know if you need me to add any more comments about what I've done and am trying to do

1 answer

✓ Accepted answer

Here you go

	local success, message = pcall(function()
		hasPass = MarketPlaceService:UserOwnsGamePassAsync(player.UserId, GamepassId)
	end)

-- just use a if statement to check if player haspass like this:
if hasPass then 

--blah blah balch asfuahsf code

4 comments

0

I'm actually looking for PromptGamePassPurchase, if user doesn't own game pass. I edited my code above a little bit from what I've just done. It prompts purchase but, for everyone. Currently I'm embracing the bug because, that's what my game is all about. Still wondering about this though. I tried using else but then it only worked for users with the game pass already.

0

I don't how to find users who don't own game pass like I said, when I tried else (refer to edited code for placement) it only worked for players with the game pass already. Tried removing ends lowering, same thing and didn't work at some points.

1

Just add a "not" after the if statement example: if not hasPass then

1

Awesome, thank you so much Jo1nts. It works as expected! I appreciate the help. Thanks again!

This discussion is preserved as it was. New answers, comments, and votes are closed.