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

How to use the teleport system for Universes?

Alright, so this is more of a question about the way to have a system where if I click a GUI, it'll teleport a player to another place in the universe. I've looked up the teleport system on the wiki, but the help they provided didn't help, let me specify.

The script I'm using:

local me = player.PlayerGui.ScreenGui.Start

function onClicked
	local player = game.Players:GetPlayerFromCharacter(click.Parent)
    	if player then
        	game:GetService("TeleportService"):Teleport(player, 31355192)
	end
end

me.MouseButton1Click:connect(onClicked) --added this part in so you knew I got this down already.

That teleport code came from the number ID on the place, I don't know if this was even the right set of numbers though (Picture link) http://prntscr.com/8gsv9x

If you need to know anything else, just tell me.

THIS EVENT IS BEING FIRED BY CLICKING A GUI BUTTON

2 answers

✓ Accepted answer

First, make sure you're writing the clicked event like this-

button.MouseButton1Down:connect(onClicked) --replace "button" with the name of your GUI button

Second, there are 2 arguments for the MouseButton1Down function- the X position of the mouse, and the Y position of the mouse. Neither of those can be used to get the player.

Instead, we can get the LocalPlayer from the script, like this:

function onClicked () --The function for the clicked event that's after this function.
	local player = game.Players.LocalPlayer
        if player then
		game:GetService("TeleportService"):Teleport( 31355192, player)
	end
end

buttonName.MouseButton1Down:connect(onClicked)

In order for this to work, it must be put into a LocalScript.

Please upvote if this helped!

10 comments

0

Dude it's not :Teleport(31355192, player) It's Teleport(player, 31355192

0

A small mistake like that is nothing to downvote someone on.

0

Fine I didn't down vote.

0

Thanks for the catch.

0

Thanks for helping so far, but now I get an error message in the developer log saying this:

0

"Unable to cast Instance of int" (next line under) I know this is the problem because under it, it shows that it came from that script on the "game:GetService" line (I've added just a little more to the original question to help)

0

Try switching around the "player" and the number, I think duckyo01 might have been wrong.

1

Also, if this is in a LocalScript, :Teleport() automatically sends the player. No need to add 'player', just :Teleport(id)

0

I still got the same error when I did both of those ideas.

0

I'm not sure if this matters, but it's being fired by clicking a GUI Button

Your Problem

Your problem is that you're accessing the player completely wrong. You're trying to use the GetPlayerFromCharacter function, but the arguments are supposed to be the character of said player that you're attempting to get. You did not supply the Character.

In fact, you don't even need to be using the GetPlayerFromCharacter function at all. Just access the player using game.Players.LocalPlayer.


Code

local me = player.PlayerGui.ScreenGui.Start
local plr = game.Players.LocalPlayer

function onClicked()
	game:GetService("TeleportService"):Teleport(player, 31355192)
end

me.MouseButton1Click:connect(onClicked)

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