Facebook
From Roblox, 2 Months ago, written in Plain Text.
Embed
Download Paste or View Raw
Hits: 46
  1. local MarketplaceService = game:GetService("MarketplaceService")
  2. local TeleportService = game:GetService("TeleportService")
  3. local Players = game:GetService("Players")
  4.  
  5. local teleporter = script.Parent
  6. local showPrompt = true
  7.  
  8. local placeID_Premium = 012345678
  9.  
  10. local function onTeleporterTouch(otherPart)
  11.  
  12.         local player = Players:GetPlayerFromCharacter(otherPart.Parent)
  13.         if not player then return end
  14.  
  15.         -- If the user already has Premium, teleport them to the Premium-only place
  16.         if player.MembershipType == Enum.MembershipType.Premium then
  17.                 TeleportService:Teleport(placeID_Premium, player)
  18.         -- Else, prompt Premium upgrade (use debounce to show it only once every few seconds)
  19.         else
  20.                 if showPrompt == false then return end
  21.                 showPrompt = false
  22.                 delay(5, function()
  23.                         showPrompt = true
  24.                 end)
  25.                 MarketplaceService:PromptPremiumPurchase(player)
  26.                 warn("Prompted Premium purchase")
  27.         end
  28. end
  29. teleporter.Touched:Connect(onTeleporterTouch)
  30.  
  31. -- If needed, use this event to know when the Premium modal is closed
  32. MarketplaceService.PromptPremiumPurchaseFinished:Connect(function(player)
  33.         warn("Premium modal closed")
  34. end)
  35.  
  36. -- Handle potential Premium purchase from outside the game while user is playing
  37. Players.PlayerMembershipChanged:Connect(function(player)
  38.         warn("Player membership changed; new membership is " .. tostring(player.MembershipType))
  39.         if player.MembershipType == Enum.MembershipType.Premium then
  40.                 -- Teleport player to the Premium-only place
  41.                 TeleportService:Teleport(placeID_Premium, player)
  42.         end
  43. end)