Premium Teleport Within Place

You can write your topic however you want, but you need to answer these questions:

  1. What I want to achieve?: I am trying to create a room within a place where if the player has premium they will be allowed to teleport to the room. The “room” is in the same place as everything else.

  2. What is the issue?: Going off of the articles related to teleporting within a place and premium purchase modal. I cannot seem to get the scripts to function properly. I figured they would have to be rearranged a little.
    Teleporting Within a Place
    Premium Purchase Modal

  3. What solutions have you tried so far?: Not really sure where to start since I’m not that great at programming so far. I try combining/modifying some things and then it errors as nil or infinite yield.

I’m trying to tie these together…

--modulescript--located in replicated storage
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Players = game:GetService("Players")
 
local TeleportWithinPlace = {}
 
-- Create remote event instance
local teleportEvent = Instance.new("RemoteEvent")
teleportEvent.Name = "TeleportEvent"
teleportEvent.Parent = ReplicatedStorage
 
function TeleportWithinPlace.Teleport(humanoid, params)
	local character = humanoid.Parent
 
	-- Freeze character during teleport if requested
	if params.freeze then
		humanoid:SetAttribute("DefaultWalkSpeed", humanoid.WalkSpeed)
		humanoid:SetAttribute("DefaultJumpPower", humanoid.JumpPower)
		humanoid.WalkSpeed = 0
		humanoid.JumpPower = 0
	end
 
	-- Calculate height of root part from character base
	local rootPartY
	if humanoid.RigType == Enum.HumanoidRigType.R15 then
		rootPartY = (humanoid.RootPart.Size.Y * 0.5) + humanoid.HipHeight
	else
		rootPartY = (humanoid.RootPart.Size.Y * 0.5) + humanoid.Parent.LeftLeg.Size.Y + humanoid.HipHeight
	end
 
	-- Teleport player and request content around location if applicable
	local position = CFrame.new(params.destination + Vector3.new(0, rootPartY, 0))
	local orientation = CFrame.Angles(0, math.rad(params.faceAngle), 0)
	if workspace.StreamingEnabled then
		local player = Players:GetPlayerFromCharacter(character)
		player:RequestStreamAroundAsync(params.destination)
	end
	character:SetPrimaryPartCFrame(position * orientation)
 
	-- Unfreeze character
	if params.freeze then
		humanoid.WalkSpeed = humanoid:GetAttribute("DefaultWalkSpeed")
		humanoid.JumpPower = humanoid:GetAttribute("DefaultJumpPower")
	end
end
 
return TeleportWithinPlace
--script--located in anchored part to be touched by player(this and the below script I believe are the two I'm trying combine in some fashion)
local ReplicatedStorage = game:GetService("ReplicatedStorage")
 
local teleportPart = script.Parent
 
local TELEPORT_DESTINATION = Vector3.new(50, 0, 50)
local TELEPORT_FACE_ANGLE = 0
local FREEZE_CHARACTER = true
 
-- Require teleport module
local TeleportWithinPlace = require(ReplicatedStorage:WaitForChild("TeleportWithinPlace"))
 
local function teleportPlayer(otherPart)
	local character = otherPart.Parent
	local humanoid = character:FindFirstChild("Humanoid")
 
	if humanoid and not humanoid:GetAttribute("Teleporting") then
		humanoid:SetAttribute("Teleporting", true)
 
		local params = {
			destination = TELEPORT_DESTINATION,
			faceAngle = TELEPORT_FACE_ANGLE,
			freeze = FREEZE_CHARACTER
		}
		TeleportWithinPlace.Teleport(humanoid, params)
 
		wait(1)
		humanoid:SetAttribute("Teleporting", nil)
	end
end
 
teleportPart.Touched:Connect(teleportPlayer)
--script--located in an anchored part(this and the above script I believe are the two I'm trying combine in some fashion)
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)
--script--currently being used(modified from 2nd and 3rd scripts I posted above) was getting differ
local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local RepStorage = game:GetService("ReplicatedStorage")
local msHolder = RepStorage:WaitForChild("ChimpModScripts")

local teleportPart = script.Parent
local showPrompt = true

local TELEPORT_DESTINATION_PREMIUM = Vector3.new(303.252, 180, 787.308)
local TELEPORT_FACE_ANGLE = 0
local FREEZE_CHARACTER = true

-- Require teleport module
local TeleportWithinPlace = require(msHolder:WaitForChild("TeleportWithinPlace"))

local function teleportPlayer(otherPart)
	local character = Players:GetPlayerFromCharacter(otherPart.Parent)
	local humanoid = character:FindFirstChild("Humanoid")
	if not humanoid then return end
		local params = {
			destination = TELEPORT_DESTINATION_PREMIUM,
			faceAngle = TELEPORT_FACE_ANGLE,
			freeze = FREEZE_CHARACTER
		}

	-- If the user already has Premium, teleport them to the Premium-only place
	if character.MembershipType == Enum.MembershipType.Premium and not character:GetAttribute("Teleporting") then
		character:SetAttribute("Teleporting", true)
		TeleportWithinPlace.Teleport(character, params)
		wait(1)
		character:SetAttribute("Teleporting", nil)
		-- 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(character)
		warn("Prompted Premium purchase")
	end
end

teleportPart.Touched:Connect(teleportPlayer)

Now it’s not giving any errors, as well as not showing me an error for premium purchase because I am actually a premium user. Should I just be creating a separate place to teleport the player to for this “room”? Not sure I just feel kind of stuck since I don’t fully understand the players, player, character and humanoid aspects. Not sure if those are what I’m messing up on. If anyone has any pointers I would greatly appreciate those. Also feel free to ask questions as I probably missed something pertaining to useful information. This is my first post, seriously FEEDBACK on anything is helpful. Thank you!

How do you plan for said premium player to activate the teleport? do they press a button to teleport to the special room, or do they instantly teleport when they join the game? if you can awnser these questons, I can help you design a script.

Actually I was able to figure things out and make it work with help from another forum post.
The article that I used is Premium only teleport pad
Thank you for your reply and offer of assistance. The community here is amazing!

1 Like