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

ANSWERED — "Unable to cast instance to int64" error – how do I fix this?

Asked by 3 years ago
Edited 3 years ago

This has already been answered

Hi everyone.

I'm relatively new to Lua, and have been experimenting with this piece of code:

local id = 000000

script.Parent.MouseButton1Click:Connect(function() -- Detects a mouse click
if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserID, id) then
        print('Success')
    else
        game.Players.LocalPlayer.PlayerGui.Gamepass.Frame.Visible = true -- Sets the executing player's frame to visible
    end
end)

In short, the code triggers once a text button is clicked and the aim is to check if the user has a gamepass or not (I've set the ID to '000000' for the example). If the user does have the gamepass, then it'll print "success", but if the user doesn't, it'll trigger a frame to open.

The particular line that I've been getting an error ("Unable to cast instance into int64") is line 4:

if game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserID, id) then

I've been trying to troubleshoot this for some time now and have seen some people suggest adding .Value to the 'id' section.

Any thoughts?

0
player isn't defined. simply add in line 1: local player = game.Players.LocalPlayer JesseSong 3916 — 3y
0
I realised I also spelled UserId incorrectly, but thanks! It works :-) User#44956 0 — 3y

Answer this question