Teleporting back and forth while being stuck in a part

Show your code, and I can help fix those issues.

1 Like

You should place the part where the player is teleported to not directly above the trigger of the other teleporter. Otherwise you will instantly trigger the other teleporter. Place it 5-10 studs apart from the trigger.

1 Like

53%20PM
Original code:


Code @Nova_MrRoyal suggested (which the last video demonstrated):

Oh wait I removed avariable on accident.

above the “local humanoid = char.humanoid” there needs to be

local char = hit.Parent

If u send me a friend request and activate Team Create I could help u manage this.

1 Like

Okay, good to know. By the way, I moved the teleports further apart and this happened:

Cuz u didnt move the teleport part with it.

1 Like

MoveTo is less glitchy than CFrame, because it ignores collisions. Make sure “TpPart” is facing the way you want the player to teleport (front surface).

local tp = workspace.TpPart
local debounce = false

script.Parent.Touched:Connect(function(hit)
        if debounce == false then
	       if hit.Parent:FindFirstChild("Humanoid") then
		    local character = hit.Parent
		    character:MoveTo(tp.Position + tp.CFrame.lookVector * 2)
                    wait(1)
	      end
              debounce = false
        end
end)

You will get an error if you use it, also :GetPlayersFromCharacter() yields the script, causing a slow down.
Remove game.ReplicatedStorage.ChangeSky:FireClient() and local player = game.Players:GetPlayerFromCharacter(char) and replace game.Workspace[player.Name].HumanoidRootPart.CFrame = teleport.CFrame with humanoid.RootPart.CFrame = teleport.CFrame

The trigger is the part the script is parented to. You should move the TpPart away not the whole teleporter

Now the script doesn’t even work.

Oh yes u are right. This is because I copied the script from one of my games

1 Like

This is after I added local char = hit.Parent

I would use @Dracolyx script, and then add a debounce to it.

Edit: Even better, he just added one! Use his!

1 Like

Yeah I just edited it adding a debounce so it’s all good now.

I just used it, but I didn’t teleport…Is that because I should have put the position in the code here:

You have to add a part named “TpPart” into workspace where you want the player to teleport, and locate the front surface of the part and rotate it towards the direction you want the player to be tped to.

1 Like

So, in the code could I just name the part portal instead of TpPart? Do you mind sending me a picture of what you mean? Thx

Open properties in studio, select the “Portal” part in workspace (rename TpPart to Portal if you want to change it), and scroll down the properties until you see surfaces. Select ‘FrontSurface’ and it will highlight the part in yellow. That is where the player will teleport in front of the part.

1 Like

The problem here is you are teleporting the player directly to the position of the other portal, which then just teleports them back and vice-versa.

To fix this, the two previous solutions should work fine: teleport the player with a slight offset and a debounce. However, a debounce won’t be useful unless you’re only using one script. Here, let’s take your code, edit it slightly and put it within on script rather than two:

Script can be placed anywhere since it references the portals from workspace.

local debounce = false

local portal1 = workspace.Portal -- path to the first portal
local portal2 = workspace.Portal2 -- path to second portal

portal1.Part.Touched:Connect(function(hit)
    local root = hit.Parent:FindFirstChild("HumanoidRootPart")
    if (not debounce) and hit.Parent:FindFirstChildOfClass("Humanoid") and root then -- check debounce in false and check for important parts of character
        debounce = true
        delay(1, function() debounce = false end) -- set debounce back to false in 1 second
        root.CFrame = CFrame.new(portal2.Part.CFrame.Position + Vector3.new(0,0,5))
        -- move the player to the other portal, but a little to the side
        -- edit the "Vector3.new(0,0,5)" to change the offset if it's too far or too close.
    end
end)

-- lets do the same thing for portal2!
portal1.Part.Touched:Connect(function(hit)
    local root = hit.Parent:FindFirstChild("HumanoidRootPart")
    if (not debounce) and hit.Parent:FindFirstChildOfClass("Humanoid") and root then
        debounce = true
        delay(1, function() debounce = false end)
        root.CFrame = CFrame.new(portal2.Part.CFrame.Position + Vector3.new(0,0,5))
    end
end)

You may need to edit the offsets for your parts but you should be able to get it right with a few trials.
Try:

Vector3.new(0,0,-5)
or
Vector3.new(5,0,0)

instead if it doesn’t work!

Edit: Used Vectors instead of CFrames as may be easier to understand

1 Like

Thanks everyone for trying to help me out! It’s been a long thread but @Nova_MrRoyal helped me through team create.