Gamepass script wont work properly

I am trying to get this script to tell if the player owns a gamepass, but it is not working.

local passId = 9179702 
 
function isAuthenticated(player)
    return game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player, passId)
end

function check()
	
	
	local victimplr = script.Parent.Parent.Parent.Parent.Parent
	
	local victim = script.Parent.Parent.Parent.Parent.Parent.Character
	
	if isAuthenticated(victimplr) then
        -- Do stuff
	
	else
		game:GetService("MarketplaceService"):PromptGamePassPurchase(victimplr, passId)
	
	
	end
	
end

script.Parent.MouseButton1Down:connect(check)

Error message

  17:42:21.627 - Unable to cast Instance to int64
17:42:21.628 - Stack Begin
17:42:21.629 - Script 'Players.DozWorl.PlayerGui.CharacterCreatorNaruto.Hair1.Adult Sasuke.Hair2', Line 6 - function isAuthenticated
17:42:21.630 - Script 'Players.DozWorl.PlayerGui.CharacterCreatorNaruto.Hair1.Adult Sasuke.Hair2', Line 16 - function kill
17:42:21.630 - Stack End
1 Like

UserOwnsGamePassAsync()'s required parameters are a Player’s UserId, and the GamePass’s ID. You’re sending “player” as in the Player (Instance/object), and not their UserId (number/int64). If you change “player” to “player.UserId” in your isAuthenticated() function, it should work.

2 Likes

On line 4, you put a player when it is supposed to be player.UserId. The reason why you are getting an error is because the player itself is an instance, and not a number value.
tldr: Change line 4 to return game:GetService(“MarketplaceService”):UserOwnsGamePassAsync(player.UserId, passId)

1 Like