Teleport Script

Hello, I am trying to make a script where you click a button and it will teleport you to a specific area.

This is the script:
local UIS = game:GetService(“UserInputService”)
local gui = script.Parent
local Back = gui.TeleportGUI.Exit
local TeleGui = gui.TeleportGUI
local Tele1 = gui.TeleportGUI.Tele1

gui.TeleportGUI.Visible = false

UIS.InputBegan:Connect(function(input)
if input.KeyCode == Enum.KeyCode.G then
gui.TeleportGUI.Visible = true
end
end)

Back.MouseButton1Click:Connect(function()
	gui.TeleportGUI.Visible = false

end)

Tele1.MouseButton1Click:Connect(function(plr)
plr.Character:MoveTo(Vector3.new(56.05, 0.5, -107.3))
end)

And this is the error:
08:55:05.775 Players.n4dar.PlayerGui.TeleportScreen.LocalScript:20: attempt to index nil with ‘Character’


image

1 Like

MouseButton1Click does not give you the player back who clicks it, also dont use MoveTo()

2 Likes

Try this for me

local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Gui = script.Parent
local Back = Gui.TeleportGUI.Exit
local TeleGui = Gui.TeleportGUI
local Tele1 = Gui.TeleportGUI.Tele1

Gui.TeleportGUI.Visible = false

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.G then
		Gui.TeleportGUI.Visible = true
	end
end)

Back.MouseButton1Click:Connect(function()
	Gui.TeleportGUI.Visible = false

end)

Tele1.MouseButton1Click:Connect(function()
	
	local Character = Player.Character
	
	local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
	
	HumanoidRootPart.Position = Vector3.new(56.05, 0.5, -107.3) -- Getting the parts position to teleport to
	
end)
1 Like

I don’t have a screen recording app but It didn’t seem to work properly.

image

It looks as if it didn’t teleport my character but my HumanoidRootPart

Btw I am fairly new to scripting.

1 Like

Ooh. I see what happened. Can you create a part at that position? and give me the path of the part

1 Like

What do you mean, “Path of the part?”
Like Coordinates?

1 Like

Like Example: game.Workspace.Part is the path or fullname

1 Like

that’s a no-no, just replace MoveTo with PivotTo and use CFrame instead

I know. I realized it doesnt work like that. So using a part would work

1 Like

game.Workspace.TP1

Thats the parts name

Thank you give me one second. to set it up


local UserInputService = game:GetService("UserInputService")
local Player = game.Players.LocalPlayer
local Gui = script.Parent
local Back = Gui.TeleportGUI.Exit
local TeleGui = Gui.TeleportGUI
local Tele1 = Gui.TeleportGUI.Tele1

local TeleportPart = game.Workspace.TP1 -- Getting the part in the workspace

Gui.TeleportGUI.Visible = false

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.G then
		Gui.TeleportGUI.Visible = true
	end
end)

Back.MouseButton1Click:Connect(function()
	Gui.TeleportGUI.Visible = false

end)

Tele1.MouseButton1Click:Connect(function()
	
	local Character = Player.Character
	
	local HumanoidRootPart = Character:FindFirstChild("HumanoidRootPart")
	
	HumanoidRootPart.Position = TeleportPart.Position -- Teleporting the player to the part
	
end)

Hmm

IT seems to be doing the same thing by extending my HumanoidRootPart
image

local Coordinates = workspace.TP1.CFrame
local Height = Character:GetPivot().Y

Character:PivotTo(Coordinates + Vector3.new(0, Height, 0))

maybe do something like this

edit: my bad, there’s a typo

Where Do I put this?

Do I put this in here?
image

yes, but you have to define the “Character” variable

Thank You!

It worked.
(extar laters)

1 Like