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

How do I fix this teleport to place or prompt purchase gamepass script?

I don't know how to code but I attempted something on my own to learn, but I can't seem to understand why it's not working. I do have no experience with Lua C so it may have been a beginner mistake. I'm trying to make it so that when you click the GUI button it prompts a Gamepass purchase if you don't own the gamepass, but if you own the gamepass it teleports you to the place.

local player = game:GetService("Players").LocalPlayer
local TeleportService = game:GetService("TeleportService")
local passID = 7949488
local mapID = 208448432
local MarketPlaceService = game:GetService("MarketplaceService")
local PlayerBoughtThisGamePass = MarketPlaceService:UserOwnsGamePassAsync(player, passID)


script.Parent.MouseButton1Down:Connect(function()
 if PlayerBoughtThisGamePass then
	TeleportService:Teleport(mapID, player)
 else 
	MarketplaceService:PromptGamePassPurchase(player, passID)
 end
end)

2 comments

0

This is the error I get - Unable to cast Instance to int64

0

If my answer worked, please accept it.

1 answer

✓ Accepted answer

MarketplaceService’s method UserOwnsGamePassAsync requires the first argument to be the UserId of the Player it is verifying the asset to. This is required so it can find the account data.

You passed the Player Object, which is only used for game-related purposes.

MarketplaceService:UserOwnsGamePassAsync(Player.UserId, GamepassId)

2 comments

0

I changed player to Player.UserId, but now on line 6 i'm getting another error : Players.MrCoolFangs.PlayerGui.GUIMEN2.Frame.Shop.Vip1.Select.LocalScript:6: attempt to index global 'Player' (a nil value)

0

Oops, I forgot Lua C is case sensitive, i change it to player.UserID and I'm no longer getting any errors

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