Player must teleport when Touching Part

Roblox Teleporting

Hello there! I’ve trying to make an elevator which will TP people to a specific location when they touch a part, but i’m unable to do so. Does anyone have any idea on how to teleport a player when a part is touched? Thank you very much!

2 Likes

You can use the MoveTo() function to move an entire model (i.e. a character)
You can also get when the player touches something by using the Touched event, and the player model would be the Parent of whatever touches it

Yes, but how would i move the player that touches that part, I know moveTo() is a function but i don’t really know how to use it.

Yes, i know that Touched works but how would i get that specific player model to move to a specific location. I don’t know what i should move. Is it the group or humanoid part? I don’t know.

Try this:

local Telepad = script.Parent
local TelePosition = workspace.TelePosition

Telepad.Touched:Connect(function(hit)
	if hit.Parent:FindFirstChild("Humanoid") then
		local HumanoidRootPart = hit.Parent:FindFirstChild("HumanoidRootPart")
		if HumanoidRootPart then
			HumanoidRootPart.CFrame = TelePosition.CFrame
		end
	end
end)
5 Likes
part = script.Parent
partwhichyourteleportingtoo = script.teleporter

Part.Touched:Connect(function(player)
player.Character.Postition:moveTo(partwhichyourteleportingtoo.Position)
end)
1 Like

Ah, I see.
MoveTo() is a function of a model, so to call it you would do

model:MoveTo(x, y, z)

The model we are referring to here would be the character, which you want to get. To do this you can use the Touched event. Events are things that fire when certain conditions are met. In the case of Touched, the event fires when the part in question is touched. You can then use the Connect() function (a function of an event) to run your code. For example:

-- Events are treated like children of an instance in this case
-- Events also return variables, which can be passed over to functions
-- In this case, the first variable it returns (which we are calling hit) is the part that hits it
script.Parent.Touched:Connect(function(hit)
    -- Because the individual limbs are triggering the event, we call the parent so that we are referring to the character model
    local character = hit.Parent 
    -- This verifies that the Parent is actually a character model; only character models should have a humanoid in them
    if character:FindFirstChild("Humanoid") then
        -- Finally, we can move the character model where we want it to go
        character:MoveTo(x, y, z)
    end
-- This would format normally, but since we're still in the Connect function we need to close it off
end)
7 Likes