Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Unable to cast Instance to int64?

I have a part, if you touch it and own the gamepass, you will get moved to a location. If you don't own it, you will be prompted the gamepass "buy screen". But I get this error:

Unable to cast Instance to int64

This is the script:

GamePassService = game:GetService('MarketplaceService')
toolGamePass = 2068240



script.Parent.Touched:Connect(function(hit)
	player = game.Players:GetPlayerFromCharacter(hit.Parent)

	if GamePassService:UserOwnsGamePassAsync(player,toolGamePass) then

	hit.Parent:MoveTo(Vector3.new(0,100,0))
	else
				GamePassService:PromptGamePassPurchase(player.PlayerId, toolGamePass)

end
end)

3 comments

1

replace 'player.PlayerId' with 'player.UserId'

0

Thanks!

0

Typo :/

1 answer

✓ Accepted answer

UserOwnsGamePassAsync needs a userId, but you passed an instance which gave you this error.

Fixed line:

if GamePassService:UserOwnsGamePassAsync(player.UserId, toolGamePass) then

PlayerId isn't a valid property of the player, unless you created it yourself, but, use player.UserId

1 comment

0

Thanks a lot! What a silly error!

This discussion is preserved as it was. New answers, comments, and votes are closed.