Why do I get this error?

This is my current code (serverscript):

	local gamePassId = 0
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr, gamePassId) then
			plr.PlayerStats.OwnsQuickRoll.Value = true
		else
			game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, gamePassId)
			plr.PlayerStats.QuickRoll.Value = false
			plr.PlayerStats.OwnsQuickRoll.Value = false
		end

and I keep getting the error “argument 1 missing or nil”, and I’m not sure why it’s happening. I’m just trying to make a gamepass popup if they do not own the gamepass.

1 Like

In which line do you get the error?
And where does the plr come from?


Additionally, you’ll need to add the gamePassId here: local gamePassId = 0 if you haven’t.
To use the UserOwnsGamePassAsync and PromptGamePassPurchase functions, you need the player’s user ID, not the player.

sorry heres the full code:

		local gamePassId = 810598857
		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr, gamePassId) then
			plr.PlayerStats.OwnsQuickRoll.Value = true
		else
			game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, gamePassId)
			plr.PlayerStats.QuickRoll.Value = false
			plr.PlayerStats.OwnsQuickRoll.Value = false
		end

		if plr.PlayerStats.OwnsQuickRoll.Value == true then

			plr.PlayerStats.QuickRoll.Value = not plr.PlayerStats.QuickRoll.Value
		end
		--print(plr.PlayerStats.QuickRoll.Value)
	end)

error is here:

		if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr, gamePassId) then

This is running in a function so that gets the plr object. Adjust it to your code

local gamePassId = 0 -- Ensure you replace 0 with your actual game pass ID

-- Assuming 'plr' is a Player object passed into this code block correctly
game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, gamePassId):andThen(function(ownsGamePass)
	if ownsGamePass then
		plr.PlayerStats.OwnsQuickRoll.Value = true
	else
		game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, gamePassId)
		if plr.PlayerStats.QuickRoll then
			plr.PlayerStats.QuickRoll.Value = false
		end
		plr.PlayerStats.OwnsQuickRoll.Value = false
	end
end):catch(function(error)
	warn("Error checking game pass: ", error)
end)

i get an error here,
game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, gamePassId):andThen(function(ownsGamePass)

"ServerScriptService.ServerScript:531: attempt to index boolean with ‘andThen’ "

I’m unfamiliar with andThen, do I need to define it or is it similar to :Connect or just then?

The correct approach is to simply call the function and use the returned value in an if statement without trying to chain it with andThen.

Also the andThen doesn’t exist my bad

What would I replace the andThen with then? Connect doesn’t work.

You replace it with this:

game:GetService("MarketplaceService"):UserOwnsGamePassAsync(plr.UserId, gamePassId)
:Then(function(ownsGamePass)
    if ownsGamePass then
        plr.PlayerStats.OwnsQuickRoll.Value = true
    else
        game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, gamePassId)
        if plr.PlayerStats.QuickRoll then
            plr.PlayerStats.QuickRoll.Value = false
        end
        plr.PlayerStats.OwnsQuickRoll.Value = false
    end
end, function(error)
    warn("Error checking game pass: ", error)
end)

Realized this issue was simplier than I thought, I just added an if statement to check if they owned it, and if they didn’t, it prompted the purchase. Heres the finished code if your interested, thanks.

	local gamepassId = 0  --gamepass id here

	plr.PlayerGui:WaitForChild("MainGui"):WaitForChild("QuickRoll").MouseButton1Click:Connect(function()
			local service = game:GetService("MarketplaceService")
		if (service:UserOwnsGamePassAsync(plr.UserId, gamepassId)) then
			if plr.leaderstats.Rolls.Value > quickRollCriteria then
				plr.PlayerStats.OwnsQuickRoll.Value = true
			else
				plr.PlayerStats.QuickRoll.Value = false
				plr.PlayerStats.OwnsQuickRoll.Value = false
			end

			if plr.PlayerStats.OwnsQuickRoll.Value == true then

				plr.PlayerStats.QuickRoll.Value = not plr.PlayerStats.QuickRoll.Value
			end
			else
				game:GetService("MarketplaceService"):PromptGamePassPurchase(plr, gamepassId)
		end
		--print(plr.PlayerStats.QuickRoll.Value)
	end)

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.