Unable to cast instance to int64

Hello, I am making a tool gamepass, but when I check if the player owns the gamepass or not, it gives me an error saying “Unable to cast instance to int64”

Here is my code:

local MarketplaceService = game:GetService("MarketplaceService")

local player = game:GetService("Players").LocalPlayer

local gpID = 62801012

if MarketplaceService:UserOwnsGamePassAsync(player, gpID) then	
	local Boombox = game:GetService("ServerStorage").Boombox:Clone()
	Boombox.Parent = player.Backpack
end

And the boombox is in ServerStorage.

You don’t mention if this is from a Server Script or Local Script but:
LocalPlayer isn’t available in a ServerScript
ServerStorage isn’t accessible from a Local Script

The reason why it doesn’t work is because :UserOwnsGamePassAsync() expects a UserId and GamepassId as its arguments, you’re passing a player object. That’s why it throws unable to cast instance to int64.

Switch your code to this and it’ll work.
if MarketplaceService:UserOwnsGamePassAsync(player.UserId, gpID) then

3 Likes

Thanks all, I tried making it userID and putting the boombox in starterPlayer and it worked.

1 Like