How do i teleport a player to some position with GUI button?

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    So i wanna teleport player to some position in same place.
  2. What is the issue? Include screenshots / videos if possible!
    No ideas how to do that.
  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I tryed use Dev hub or youtube tutorials, but all tutorials about teleport between places, but i need teleport within places

My script:


local button = script.Parent

local TELEPORT_DESTINATION = Vector3.new(-184.039, 1.5, -425.691)
local TELEPORT_FACE_ANGLE = 0
local FREEZE_CHARACTER = true

local teleportEvent = ReplicatedStorage:WaitForChild("TeleportEvent")

local function onButtonActivated()
	local params = {
		destination = TELEPORT_DESTINATION,
		faceAngle = TELEPORT_FACE_ANGLE,
		freeze = FREEZE_CHARACTER
	}
end

button.Activated:Connect(onButtonActivated)
3 Likes

To teleport a player simply set their HRP’s Position

player.Character.HumanoidRootPart.Position = dest
1 Like

Ughhh, i’m don’t understand teleporting a lot, so i don’t get it(i took that script frm dev hub, but it’s don’t work)

Okay so in your case all you have to do in your script is:

local button = script.Parent

local TELEPORT_DESTINATION = Vector3.new(10, 10, 10) -- Or if you want to teleport to a parts position use game.Workspace.Part (Or the path to your part).Position (ex: game.Workspace.Part.Position)

local function onButtonActivated()
    local player = game.Players.LocalPlayer
    local char = player.Character
    local HRP = char.HumanoidRootPart
    HRP.Position = TELEPORT_DESTINATION
end

script.Parent.MouseButton1Click:Connect(onButtonActivated)

Thanks you a lot gonna test it


ummmm


For some reason only my cam teleport, not character

So the thing is that you should teleport root with CFrame.
And the easiest way to do that is with a part
so make a anchored cantcollide invisible part and copy this code:

local plr = game.Players.LocalPlayer
local teleportpart = workspace.TeleportPart

function teleport()
	if plr.Character then
		if plr.Character.HumanoidRootPart then
			plr.Character.HumanoidRootPart.CFrame = teleport.CFrame
		end
	end
end

script.Parent.MouseButton1Click:Connect(teleport)

Place this script inside the textbutton
Change teleportpart to your part where the player teleports

Noticed you haven’t used the variable “teleportpart”. Is there a reason for that? Otherwise there’s no need to put time and energy to type it out.

oops, teleport needs to be teleportpart, like this:

local plr = game.Players.LocalPlayer
local teleportpart = workspace.TeleportPart

function teleport()
	if plr.Character then
		if plr.Character.HumanoidRootPart then
			plr.Character.HumanoidRootPart.CFrame = teleportpart.CFrame
		end
	end
end

script.Parent.MouseButton1Click:Connect(teleport)

You must write this code in the Local scripts

so what???

Are you didn’t see he write remote events

When the button is clicked, fire the RemoteEvent and handle the teleporting in a Script via :SetPrimaryPartCFrame()

LocalScript

local replicatedStorage = game:GetService("ReplicatedStorage")
local teleportEvent = replicatedStorage:WaitForChild("TeleportEvent") 
local cooldown = false

script.Parent.MouseButton1Click:Connect(function()
    if cooldown then return end cooldown = true
    teleportEvent:FireServer()
    wait(1) -- Cooldown time
    cooldown = false
end)

Script:

local replicatedStorage = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")

replicatedStorage.teleportEvent.OnServerEvent:Connect(function(player)
    local player = players:FindFirstChild(player.Name)
    if not player then return end
    player.Character:SetPrimaryPartCFrame(CFrame.new(-184.039, 1.5, -425.69))
end)

My bad if there are any spelling mistakes since I typed this up here. Also, I implemented a button cooldown system so that the RemoteEvent isn’t abused.

what is point of events when u dont need them. this script works without

why so complicated when u can do simple lol

local plr = game.Players.LocalPlayer
local teleportpart = workspace.TeleportPart

function teleport()
	if plr.Character then
		if plr.Character.HumanoidRootPart then
			plr.Character.HumanoidRootPart.CFrame = teleportpart.CFrame
		end
	end
end

script.Parent.MouseButton1Click:Connect(teleport)

Exactly that what was I mean like that

Right.


local button = script.Parent

local TELEPORT_DESTINATION = CFrame.new(-184.039, 1.5, -425.691)
local TELEPORT_FACE_ANGLE = 0
local FREEZE_CHARACTER = true

local function onButtonActivated()
    local c = game.Players.LocalPlayer.Character
	local params = {
		destination = TELEPORT_DESTINATION,
		faceAngle = TELEPORT_FACE_ANGLE,
		freeze = FREEZE_CHARACTER
	}

    c:PivotTo(params.destination * CFrame.new(0, c.Humanoid.HipHeight, 0) * CFrame.Angles(0, math.rad(params.faceAngle), 0))
    if params.freeze then
        c.PrimaryPart.Anchored = true
    end
end

button.Activated:Connect(onButtonActivated)

Well, I guess you can do it however you want. It all depends on your game’s security. (anti exploits)