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

Teleport to another game if gamepass purchase is successful?

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

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)


5 comments

0

Thanks for the help!

0

Anytime

0

I just tried it out and it didn't work.

0

edited the question, try the new script

0

Still doesn't work but I fixed it myself below, Thanks anyways.

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)

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