Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

Why does this teleport script turn you upside down? [SOLVED]

Asked by
JJ_B 250 Moderation Voter
9 years ago

I wrote this teleport script the other day and I just can not work out why it turns you upside down when you teleport or how to rectify it. Here is the script:

char = game.Players.LocalPlayer.Character
destination = game.Workspace.Bridged

function teleporter()
char.Torso.Anchored = true
char.Torso.CFrame = destination.CFrame + Vector3.new(0,0,0)
wait(0.2)
char.Torso.Anchored = false
end

script.Parent.MouseButton1Click:connect(teleporter)

Help would be much appreciated.

2 answers

Log in to vote
2
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
9 years ago

It looks to me that destination is your issue. Since you're using its CFrame (as opposed to its Position) as the teleportation 'goal', the rotation of destination determines the rotation of the Torso after the teleportation.

There's a very simple way to get around this:

char = game.Players.LocalPlayer.Character
destination = game.Workspace.Bridged

function teleporter()
char.Torso.Anchored = true
char.Torso.CFrame = CFrame.new(destination.Position) + Vector3.new(0,0,0)
wait(0.2)
char.Torso.Anchored = false
end

script.Parent.MouseButton1Click:connect(teleporter)

CFrame.new(destination.Position) is, effectively, destination.CFrame, but with a Rotation of (0, 0, 0).

0
Thanks a lot! JJ_B 250 — 9y
Ad
Log in to vote
0
Answered by 9 years ago

I would suggest using :MoveTo() on the character, instead of actually changing the torso's position.

:MoveTo() will move your character around, basically teleporting.

Let me give you an example:

Destination = game.Workspace.DestinationBrick

game.Workspace.TeleportingBrick.Touched:connect(function(hit)
local Detector = hit.Parent:FindFirstChild("Torso")
if Detector then

hit.Parent:MoveTo(Destination.Position) -- It's a shorter, and easier method.
end)

Hope this helped! Please upvote if it did.

Answer this question