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

How do I teleport a player when a GUI is clicked?

Asked by
NecoBoss 194
10 years ago

Okay so I have this whole script working but the teleport doesn't work:

wait(1)
button = script.Parent
local dbounce = false
function hi()
    if dbounce == false then
        dbounce = true
        script.Parent.Parent.TextButton1.LocalScript:Destroy()
    game.ReplicatedStorage.LinkedSword:clone().Parent = game.Players.LocalPlayer.Backpack
    game.ReplicatedStorage.RocketLauncher:clone().Parent = game.Players.LocalPlayer.Backpack
    for i = 0.3, 1, 0.1 do
        wait(0.1)
        script.Parent.BackgroundTransparency = i
        script.Parent.Parent.BackgroundTransparency = i
        script.Parent.Parent.TextButton1.BackgroundTransparency = i
        script.Parent.Parent.Parent.Label.BackgroundTransparency = i
        script.Parent.Parent.Parent.Label.TextLabel.TextTransparency = i
    end
    script.Parent.Parent.Visible = false 
    game.Players.LocalPlayer.Character.Torso.CFrame.Position = Vector3.new(0,50,0) --- Why doesn't this work?
    end
end

script.Parent.MouseButton1Click:connect(hi)

3 answers

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

There are two ways to teleport someone. I'll start with your method, which is to use CFrame.

It's not game.Players.LocalPlayer.Character.Torso.CFrame.Position = Vector3.new(). It should be, game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new()

The second method is to use MoveTo on the character model itself. So, game.Players.LocalPlayer.Character:MoveTo(Vector3.new())

Wiki articles: MoveTo() CFrame

Ad
Log in to vote
3
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
10 years ago

CFrame doesn't have a Position property. (It does have a p property which is the position of the CFrame, but that is read only)

Just set the CFrame of the Torso.

We construct a new CFrame from a Vector3 by just passing the Vector3 to the CFrame.new constructor.

game.Players.LocalPlayer.Character.Torso.CFrame = CFrame.new( Vector3.new(0,50,0) );
Log in to vote
0
Answered by 10 years ago
function Click()
script.Parent.Parent.Parent.Parent.Character.Torso.CFrame = CFrame.new(-111.2, 891.5, -277) --change to the place you want to teleport to!
end

script.Parent.MouseButton1Down:connect(Click)

That is mine for my game I hope it helps.

Answer this question