Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Unable to cast Instance to int64?

Asked by
Oficcer_F 207 Moderation Voter
5 years ago
Edited 5 years ago

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)

1
replace 'player.PlayerId' with 'player.UserId' hellmatic 1523 — 5y
0
Thanks! Oficcer_F 207 — 5y
0
Typo :/ Oficcer_F 207 — 5y

1 answer

Log in to vote
1
Answered by
Rare_tendo 3000 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

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

0
Thanks a lot! What a silly error! Oficcer_F 207 — 5y
Ad

Answer this question