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

Why Am I Getting an Error in this Simple Game Pass Script?

I'm trying to make a brick that, when it is clicked, prints "Game Pass" if the user owns the game pass or otherwise prompts the user to buy the game pass. This is what I have; however, unfortunately, it doesn't work:

script.Parent.Click.MouseClick:Connect(function(player)
	if player then
		local owns = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player, 00000)
		if owns then
			print("Game Pass")
		else
			game:GetService("MarketplaceService"):PromptGamePassPurchase(player, 00000)
		end
	end
end)

I get the following error when calling the UserOwnsGamePassAsync function: "Unable to cast Instance to int64"

Any help would be greatly appreciated!

1 answer

It must be player.UserId, not player. player is an Instance, the first variable should be a player's userid. This applies to both of them by the way.

So:

script.Parent.Click.MouseClick:Connect(function(player)
    if player then
        local owns = game:GetService("MarketplaceService"):UserOwnsGamePassAsync(player.UserId, 00000)
        if owns then
            print("Game Pass")
        else
            game:GetService("MarketplaceService"):PromptGamePassPurchase(player.UserId, 00000)
        end
    end
end)

4 comments

0

This works, thank you! However, why is it that, when working with a brick that is touched, I can define player in the following manner and not have to include the ".UserId" portion? player = game.Players:GetPlayerFromCharacter(hit.Parent)

0

Because MarketplaceService uses UserIds. GetPlayerFromCharacter gets a Player, an Instance, from the player's character. Also please mark it as answered :)

0

I apologize for the trouble, but where do I mark your question as answered? This is my first question on the site haha.

0

I never asked a question before, not sure lol.Uhh can you keep checking for it? It should be somewhere visible

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