PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Jun 26 2018, 11:09 AM PST

This code sample causes a Part to teleport any players that touch it to a specific position defined by a “TeleportPosition” Vector3Value.

-- Paste me in a Script inside a Part
local part = script.Parent
-- A Vector3Value to hold the Teleport target position
-- Tip: Prefix variables of "Value-" objects with "v"
local vTeleportPosition = part.TeleportPosition 

local function onTouch(otherPart)
	-- First, find the HumanoidRootPart. If we can't find it, exit.
	local hrp = otherPart.Parent:FindFirstChild("HumanoidRootPart")
	if not hrp then return end
	
	-- Now teleport by setting the CFrame to one created from
	-- the stored in TeleportPosition
	hrp.CFrame = CFrame.new(vTeleportPosition.Value)
end

part.Touched:connect(onTouch)