Creating a script that teleports to a certain position when a button is clicked

Hi, I want to create a script that when a player presses a button, they get teleported to a certain position.
I would like some help or information about how to create this script. Thanks!

3 Likes

If you are using a ClickDetector you can either use :MoveTo() or :SetPrimaryPartCFrame() on their character.

1 Like

you gotta make a local script first use MouseButton1Click function to check if gui is clicked then make a variable called plr which contains the local player then find the character of the local player then change the CFrame of the humanoidrootpart to wherever you want

1 Like

Thanks, but I’m not using a Gui.

2 Likes

If I do :MoveTo(10, 10, 10), will it teleport the player to that position?

1 Like

It will do that. You can use either but I personally prefer SetPrimaryPartCFrame().

1 Like

moveto function will make the player walk to that position

1 Like

Isn’t SetPrimaryPartCFrame() about CFrames?

Oh I’m stupid. Yeah it is CFrames. Are you getting a part’s position or putting co-ordinates?

So, I’m trying to teleport the player to a position that I choose when the player clicks the ClickDetector Part

1 Like

:MoveTo() will teleport the player without changing the orientation.
image

:SetPrimaryPartCFrame() will teleport at the part’s CFrame.
image

1 Like

Ok, Can you tell me how I can put :MoveTo()? Do I put it after the function?
Sorry, I’m not good at scripting.

Gui

script.Parent.MouseButton1Click:Connect(function()
	local Player = game.Players.LocalPlayer
	local Character = Player.Character
	local Root = Character:FindFirstChild("HumanoidRootPart")
	local Part = game.Workspace.Teleports.Position1
	if Root ~= nil then
		Root.CFrame = CFrame.new(Part.Position)
	end
end)

ClickDetector

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
	local Character = Player.Character
	local Root = Character:FindFirstChild("HumanoidRootPart")
	local Part = game.Workspace.Teleports.Position1
	if Root ~= nil then
		Root.CFrame = CFrame.new(Part.Position)
	end
end)

Screenshot
Capture

2 Likes

Script 1:
local part = game.Workspace.ExamplePart
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
plr.Character:MoveTo(part.Position)
end)

Script 2:
local part = game.Workspace.ExamplePart
script.Parent.ClickDetector.MouseClick:Connect(function(plr)
plr.Character:SetPrimaryPartCFrame(part.CFrame)
end)

Thank you for your information, but I’m not using a Gui for this.

I will test this script out and tell you. :grinning:

1 Like

There is gui and click detector.
Just tell us what are you using to make the teleport

Oh, sorry, I didn’t see that you wrote a ClickDetector script. I’m using a ClickDetector.

Here is the roblox folder if you want to test it
Teleport.rbxl (26,1 Ko)

3 Likes

Ok, I will check it out, thanks!