I'm trying to make a gamepass, and make it see if the player owns the gamepass, if not then a gamepass will get prompted.
Here is my script (it's a local script):
local gamepassID = 49956565
local MPS = game:GetService('MarketplaceService')
local plr = game.Players.LocalPlayer
local button = plr.PlayerGui.GamepassShopGUI.MainFrame.TwoTimesClicksFrame.BuyButton
button.Activated:Connect(function()
if MPS:UserOwnsGamePassAsync(plr, gamepassID) then
button.Text = 'You already own the gamepass'
else
MPS:PromptGamePassPurchase(plr, gamepassID)
end
end)
The error is on line 8.
Thank you for reading.

5 comments
The first argument to
UserOwnsGamePassAsync()should be the player's user id, not the player object. Also, this more than likely needs to be handled in a server-side script.I need to do it when a player presses a gui button, so I used a remote event, but now it says "Unable to cast value to Object"
I have found out the answer now.
Hey Buddy make sure the game pass features giving script is in ServerScriptService in case of Exploiters.
Please remember to add "[SOLVED]" to your question title when you resolve it without accepting any answers. Thanks