I have a teleporter that I'm trying to make that sends you to a shop in my game. The problem is the brick I'm trying to make it teleport you to also sends you back. I've added a debounce to make sure players can't infinity get teleported between the two bricks. I've tried this script and it doesn't teleport you like I'm trying to make it do and there's error in output. If anyone has a clue as to why this doesn't work, that would be awesome.
01 | local teleportbrick 1 = workspace:WaitForChild( "TeleportBrick1" ) |
02 | local teleportbrick 2 = workspace:WaitForChild( "TeleportBrick2" ) |
03 |
04 | local waittime = 3 |
05 | local touched = false |
06 |
07 | local function teleport(position) |
08 | return function (hit) |
09 | if not touched then |
10 | touched = true |
11 | local character = game.Players:GetPlayerFromCharacter(hit.Parent).Character |
12 | local head = character and character:FindFirstChild( "Head" ) |
13 | if head then |
14 | head.CFrame = position |
15 | end |
Hi.
:MoveTo() is meant to walk the player to that location.
If you're looking to teleport you should change the CFrame to the torso to the new position.
A small example:
1 | part = script.Parent |
2 | tp = game.Workspace.tp 2 |
3 |
4 | part.Touched:connect( function (hit) |
5 | if hit.Parent.Humanoid then |
6 | hit.Parent.Torso.CFrame = CFrame.new(tp.CFrame.X, tp.CFrame.Y, tp.CFrame.Z) |
7 | end |
8 | end ) |
The above is an example that should work.
01 | -- Untested, try this script.. |
02 | local PartToTouch = script.Parent -- if you touch that certain part |
03 | PartToTouch.Touched:connect( function () |
04 | local GoTo = game.worskpace.TeleportPart -- First off all change that to the part u wanna teleport to |
05 |
06 | local char = game:GetService( "Players" ).LocalPlayer:GetCharacter() -- get the players character |
07 | local torso = char.Torso -- get the players torso |
08 |
09 | torso.Position = Goto.Position + Vector 3. new( 0 , 10 , 0 ) |
10 | end ) |
I guess this will work