Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do i make a GUI that teleport a player when clicked?

How do I make a GUI that teleports a player when clicked? I really have no idea where to start with this.

1 comment

0

teleport as in move the player ingame or to another place using the teleport service?

3 answers

There are two answers to your question, as there are two meanings of 'teleport'.

Teleport Ingame:


Teleporting in game is as easy as moving the character model to the location you want to move them to;

local player=game.Players.LocalPlayer

--Let's start by making a function to move the player (not really needed, but why not?)
function teleportPlayer(position) --the parameter should be a Vector3
	player.Character:MoveTo(position)
end

--assuming this script will be in the GUI itself
script.Parent.Button.MouseButton1Down:connect(function() --"Button" is the name of the TextButton
	teleportPlayer(Vector3.new(0,1,0)) --The vector3 is where the player will be moved to.
end)

Teleport to a different game:


Teleporting to a different game is just as easy;

local player=game.Players.LocalPlayer

--Let's make another function (again, not really needed, but why not?)
function teleportPlayer(placeId,plr) --the parameter should be a Vector3
	game:GetService("TeleportService"):Teleport(placeId,plr)
end

--assuming this script will be in the GUI itself
script.Parent.Button.MouseButton1Down:connect(function() --"Button" is the name of the TextButton
	teleportPlayer(155615604,player) --Prison life, local player
end)

This LocalScript will teleport the player to a part's CFrame:

button = script.Parent
player = game.Players.LocalPlayer
function teleport()
	local torso = player.Character.Torso 
	torso.CFrame = game.Workspace.Part.CFrame 

end

button.MouseButton1Click:connect(teleport)

The script goes inside a TextButton. You get the idea.

2 comments

0

Explain it a bit more - 'you get the idea' does not help at all.

0

Don't feel like it.

Please follow the instructions before using the script make a Screen GUI called Teleport then insert a text button into the teleport GUI and then insert a script into the text button and please replace the numbers by the vector with the position of the brick to which the player is being placed by using properties

torso = game.Players.LocalPlayer.Character.Torso 
pos = Vector3.new(0, 0, 0)

function getteleportlocation(location) local x = location.x local y = location.y local z = location.z x = x + math.random(-1, 1) z = z + math.random(-1, 1) y = y + math.random(2, 3) local cf = torso.CFrame local lx = 0 local ly = y local lz = 0 return CFrame.new(Vector3.new(x,y,z), Vector3.new(lx,ly,lz)) end 

function onClicked(GUI)
	torso.CFrame = getteleportlocation(pos)
end 

script.Parent.MouseButton1Click:connect(onClicked)

Please note this only for in game teleport to new vectors using simple functions this is not an example of a well put together teleport script

This discussion is preserved as it was. New answers, comments, and votes are closed.