Prompt player to purchase Premium when stepping on a block without teleporting

So, I am making a game that will have premium benefits. I read something about this that prompted the purchase of premium upon stepping on a certain part, however the script then teleports the user to a different place if they make the purchase. How could I prompt purchase of premium without the teleportation sector of the script?

1 Like

Hi,

Could you please provide the script for us to see?

1. local MarketplaceService = game:GetService("MarketplaceService")
2. local TeleportService = game:GetService("TeleportService")
3. local Players = game:GetService("Players")
 * local teleporter = script.Parent
4. local showPrompt = true
 * local placeID_Premium = 012345678
 * local function onTeleporterTouch(otherPart)
 * local player = Players:GetPlayerFromCharacter(otherPart.Parent)
5. if not player then return end
 * -- If the user already has Premium, teleport them to the Premium-only place
6. if player.MembershipType == Enum.MembershipType.Premium then
7. TeleportService:Teleport(placeID_Premium, player)
8. -- Else, prompt Premium upgrade (use debounce to show it only once every few seconds)
9. else
10. if showPrompt == false then return end
11. showPrompt = false
12. delay(5, function()
13. showPrompt = true
14. end)
15. MarketplaceService:PromptPremiumPurchase(player)
16. warn("Prompted Premium purchase")
17. end
18. end
19. teleporter.Touched:Connect(onTeleporterTouch)
 * -- If needed, use this event to know when the Premium modal is closed
20. MarketplaceService.PromptPremiumPurchaseFinished:Connect(function(player)
21. warn("Premium modal closed")
22. end)
 * -- Handle potential Premium purchase from outside the game while user is playing
23. Players.PlayerMembershipChanged:Connect(function(player)
24. warn("Player membership changed; new membership is " .. tostring(player.MembershipType))
25. if player.MembershipType == Enum.MembershipType.Premium then
26. -- Teleport player to the Premium-only place
27. TeleportService:Teleport(placeID_Premium, player)
28. end
29. end)

This is the script, but I just want it to prompt the purchase not teleport them.

Do you mean not teleport them to the premium-only place? If so, just remove this code and make sure it runs.

26. -- Teleport player to the Premium-only place
27. TeleportService:Teleport(placeID_Premium, player)

You also will then have to fix this:

6. if player.MembershipType == Enum.MembershipType.Premium then
7. TeleportService:Teleport(placeID_Premium, player)

I cannot test if this will work because I don’t have premium myself, but this is the code handling the teleportation.

This is what I got in the output.

image

You covered the end of the error, what does it say?

image

You just cant teleport in roblox studio. You must test it in-game.

1 Like

I don’t have premium.

30 chars

This is the message my friend with premium got.

I just removed all the teleporting stuff.
(And indented your code properly)

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local teleporter = script.Parent
local showPrompt = true

local function onTeleporterTouch(otherPart)
	local player = Players:GetPlayerFromCharacter(otherPart.Parent)
	if not player then return end
	-- If the user already has Premium, teleport them to the Premium-only place
	if player.MembershipType ~= Enum.MembershipType.Premium then
		if showPrompt == false then return end
		showPrompt = false
		delay(5, function()
			showPrompt = true
		end)
		MarketplaceService:PromptPremiumPurchase(player)
		warn("Prompted Premium purchase")
	end
end

teleporter.Touched:Connect(onTeleporterTouch)

-- If needed, use this event to know when the Premium modal is closed
MarketplaceService.PromptPremiumPurchaseFinished:Connect(function(player)
	warn("Premium modal closed")
end)

-- Handle potential Premium purchase from outside the game while user is playing
Players.PlayerMembershipChanged:Connect(function(player)
	warn("Player membership changed; new membership is " .. tostring(player.MembershipType))
end)
2 Likes

Thank you so much for your help. :heart: :slight_smile: