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

Teleport to another game if gamepass purchase is successful?

Asked by 5 years ago
Edited 5 years ago

So I made a script that when you click on a button in a GUI it would let you buy the gamepass but if someone did buy the gamepass I want them to be teleported to the game "3650823073" the problem is I don't know how to make it verify if someone bought the gamepass or not because right now it would teleport people instantly even if they didn't buy the gamepass. Thanks for the help!

script.Parent.MouseButton1Click:connect(function() 
    game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, 4725748)
game:GetService("TeleportService"):Teleport(3650823073)

end
end)

2 answers

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Sorry for indentation!

script.Parent.MouseButton1Click:connect(function() 
       game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, 4725748)

    game.MarketplaceService.PromptPurchaseFinished:Connect(function()
        if game.MarkerplaceService:PlayerOwnsAsset(game.Players.LocalPlayer,4725748) then
            game:GetService("TeleportService"):Teleport(game.Players.LocalPlayer,3650823073)
        end
    end)
end)


0
Thanks for the help! Avia_Robby 42 — 5y
0
Anytime mybituploads 304 — 5y
0
I just tried it out and it didn't work. Avia_Robby 42 — 5y
0
edited the question, try the new script mybituploads 304 — 5y
0
Still doesn't work but I fixed it myself below, Thanks anyways. Avia_Robby 42 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

Thanks to some help from a few people on the discord server I was able to get it working with this code below.

local MarketplaceService = game:GetService("MarketplaceService")
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function() 
    game:GetService("MarketplaceService"):PromptGamePassPurchase(game.Players.LocalPlayer, 4725748)
end)
    game.MarketplaceService.PromptGamePassPurchaseFinished:Connect(function()
    if game.MarketplaceService:UserOwnsGamePassAsync(player.UserId,4725748) then
    game:GetService("TeleportService"):Teleport(3650823073)
    end
end)

Answer this question