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.
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.
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)
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)