Keep getting error Unable to cast Instance to int64

Hi,

I’m pretty new to Lua and I saw that I can use this tycoon kit made by ZedNov, so I decided to use it.

I want to make it so that if you want to buy a gamepass (ex. a car), it prompts you, and once you purchase it and join another game it still gives you the car. The only problem is whenever I step on the button with the gamepass, it returns the error “Unable to cast Instance to int64”. I have no idea what that means. I tried looking on Google and other posts but there are not much people also getting this specific error out there. What does the error mean?

Code that checks if player has gamepass

				local player = game.Players:GetPlayerFromCharacter(hit.Parent)
				if v.Head.CanCollide == true then
					if player ~= nil then
						if script.Parent.Owner.Value == player then
							if hit.Parent:FindFirstChild("Humanoid") then
								if hit.Parent.Humanoid.Health > 0 then
									local PlayerStats = game.ServerStorage.PlayerMoney:FindFirstChild(player.Name)
									if PlayerStats ~= nil then
										if (v:FindFirstChild('Gamepass')) and (v.Gamepass.Value >= 1) then
											if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player,v.Gamepass.Value) then -- returns Unable to cast Instance to int64
												Purchase({[1] = v.Price.Value,[2] = v,[3] = PlayerStats})
												print("hi")

Only the line game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player,v.Gamepass.Value) then returns the error.
Once again, I am pretty new to Lua so I apologize if there is a simple solution to this

2 Likes

The problem is that userOwnsPassAsync is supposed to be given a userid and a gamepassid, but is being fed a player object rather than a userid. This could be fixed by replacing this line:

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player,v.Gamepass.Value) then

with this:

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId,v.Gamepass.Value) then
3 Likes