Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

How to use the teleport system for Universes?

Asked by
Troidit 253 Moderation Voter
8 years ago

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

Log in to vote
0
Answered by 8 years ago

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!

0
Dude it's not :Teleport(31355192, player) It's Teleport(player, 31355192 duckyo01 120 — 8y
0
A small mistake like that is nothing to downvote someone on. HungryJaffer 1246 — 8y
0
Fine I didn't down vote. duckyo01 120 — 8y
0
Thanks for the catch. grasheeno 70 — 8y
View all comments (6 more)
0
Thanks for helping so far, but now I get an error message in the developer log saying this: Troidit 253 — 8y
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) Troidit 253 — 8y
0
Try switching around the "player" and the number, I think duckyo01 might have been wrong. grasheeno 70 — 8y
1
Also, if this is in a LocalScript, :Teleport() automatically sends the player. No need to add 'player', just :Teleport(id) TheStudentPilot 75 — 8y
0
I still got the same error when I did both of those ideas. Troidit 253 — 8y
0
I'm not sure if this matters, but it's being fired by clicking a GUI Button Troidit 253 — 8y
Ad
Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
8 years ago

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)

Answer this question