Teleporting a player

I’m trying to make it where when a player clicks a button they teleport to a certain location. I’m new to scripting and need some help. This is what I have so far and its giving me errors:

local gui = game.Players.LocalPlayer.PlayerGui:WaitForChild("ScreenGui").ImageLabel
local TouchDestination11 = game.Workspace:WaitForChild("TouchDestination11")

function onClicked(player)
	if gui.Visible == true then
		player:FindFirstChild("HumanoidRootPart").CFrame = TouchDestination11.CFrame
	end
end

workspace.coin.ClickDetector.MouseClick:Connect(onClicked)

Thanks.

1 Like

Always check developer.roblox.com for things like these:
Teleporting Within a Place

What errors are you getting?

1 Like

Try this,

[Without Remote]:

local Players = game:GetService("Players")
local Player = Players.LocalPlayer
local gui = script.Parent
local TouchDestination11 = game.Workspace:WaitForChild("TouchDestination11")

function onClicked()
	Player.Character:PivotTo( TouchDestination11.CFrame) 
end

workspace.coin.ClickDetector.MouseClick:Connect(onClicked)

image

1 Like

What the above script shows should work. The issue with your script was you were attempting to get the HumanoidRootPart inside the Player object, and not the Player’s Character model. Which is fixed by referencing Player.Character.

1 Like

Thank you! It works exactly how I wanted it too.

Yea I see now. Thank you very much.