Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

✓ Accepted answer

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

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) );
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.

This discussion is preserved as it was. New answers, comments, and votes are closed.