How to teleport player to specific location?

Hello! How can I make it so that when the player presses escape and then clicks on the reset button, be teleported to a specific location?

My idea is to teleport them to a location that I can choose using CFrame. Does anyone know how I could do that?

1 Like

I’m going to give a very simplified version of this for you. The way that I’ve been told to use is PivotTo, theres a scripting example of what you’d need to put into your code below.

local Character = game.Workspace:FindFirstChild("PlayerName")--[[Change this to what the character of the person you want to change is,]]
Character:PivotTo() -- Put the CFrame of where you want the person to go here.

I was thinking of something like this, would it work too?

local Players = game:GetService("Players")

local function teleportToLocation(player)
    local teleportLocation = Vector3.new(0, 100, 0)
    player.Character:SetPrimaryPartCFrame(CFrame.new(teleportLocation))
end

Players.PlayerAdded:Connect(function(player)
    print(player.Name .. " has joined the game.") 
    player.CharacterAdded:Connect(function(character)
        print(player.Name .. " has spawned.") 
        character.Humanoid.Died:Connect(function()
            if character.Humanoid.Health == 0 then
                print(player.Name .. " has respawned using the reset button.")
                respawns using the reset button
                teleportToLocation(player)
            end
        end)
    end)
end)
1 Like

Not exactly,
Could that work…?, possibly; but there’s a much easier way to do this that’s less confusing.

First, assuming you want the player to die, you don’t need to check if the characters health is 0, as when the Died event is fired… the players health will be 0.

Now, if you want the player to teleport to a specific location when they reset… then almost everything is good here. All you need to do is change SetPrimaryPartCFrame to PivotTo, and it should work. (NOTE: This will put the player in the exact position given, even if there’s an object blocking the area. If you don’t want this to happen, use @TomPlays63’s method and change SetPrimaryPartCFrame to MoveTo)

You can use the plr:MoveTo() – do note this only moves the player and does not change the orientation, basically just a vector3 instead of a cframe.

2 Likes

You do not need to listen for the player to die, you can just replace the function of the reset button.

local resetBindable = Instance.new("BindableEvent")
resetBindable.Event:connect(function()
    -- Implement custom reset logic here
end)

game:GetService("StarterGui"):SetCore("ResetButtonCallback", resetBindable)

Also, I suggest using plr:MoveTo() like @TomPlays63 has suggested.

6 Likes

For teleporting… MoveTo has the possibility of walking a player to their destination, and can be affected by parts in the way. PivotTo will strictly teleport the player to the location, no matter what’s in the way.

1 Like

Just use that, I added the teleport logic associated to the custom ResetButtonCallback @Entildo mentioned

5 Likes

Thank you all very much for your comments, they were very helpful! I have marked the last answer as a solution since it was the one that best suited my needs, thank you all! :smiley:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.