So I’m using the script provided by ROBLOX where if you own premium you get teleported to a specific place and if you don’t it shows the purchase prompt to buy premium so that you can get access to the teleporter, now I was wondering how do I make it so that when this part is touched it will teleport the player (if they own premium) but instead of teleporting to another experience, I want it to teleport the player to a specific part I have in the same game?
The script:
local MarketplaceService = game:GetService("MarketplaceService")
local TeleportService = game:GetService("TeleportService")
local Players = game:GetService("Players")
local teleporter = script.Parent
local showPrompt = true
local placeID_Premium = 012345678
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
TeleportService:Teleport(placeID_Premium, player)
-- Else, prompt Premium upgrade (use debounce to show it only once every few seconds)
else
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))
if player.MembershipType == Enum.MembershipType.Premium then
-- Teleport player to the Premium-only place
TeleportService:Teleport(placeID_Premium, player)
end
end)
-- If the user already has Premium, teleport them to the Premium-only place
if player.MembershipType == Enum.MembershipType.Premium then
TeleportService:Teleport(placeID_Premium, player)
-- Else, prompt Premium upgrade (use debounce to show it only once every few seconds)
else
The above snippet is from the upper middle of your script.
The line that says TeleportService:Teleport(placeID_Premium, player) is whats doing the teleportation in this script.
Instead of keeping whats currently there, you will want to delete that one line and replace it with something similar to the following:
local location = Vector3.new(0, 0, 0)
player.Character:SetPrimaryPartCFrame(CFrame.new(location))
In this case, you will want to change the location I’ve provided with the one you want the player to be teleported to.
Sorry for asking again, I was just wondering, I tried the script in my game and it works perfectly except for one thing, I tried it on my alt, and when I touched the part it did show the purchase premium prompt but it still teleported the player even though they don’t have premium, do you have any idea how I can fix this?
I believe I figured it out and it seems to be working fine, so I’ll put the code here in case someone wants to use this in the future (apologies if the code looks horrible lol, I’m not a good scripter)
Code:
local TeleportPart = script.Parent
local mps = game:GetService("MarketplaceService")
local isOpen = false
script.Parent.Touched:Connect(function(hit)
local char = hit.Parent
local plr = game.Players:GetPlayerFromCharacter(char)
if not plr then return end
if plr.MembershipType == Enum.MembershipType.Premium then
if hit and hit.Parent and hit.Parent:FindFirstChild("HumanoidRootPart") then
hit.Parent.HumanoidRootPart.Position = script.Parent.Parent.PremiumTP.Position
end
else
mps:PromptPremiumPurchase(plr)
end
end)