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
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!
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
.
local me = player.PlayerGui.ScreenGui.Start local plr = game.Players.LocalPlayer function onClicked() game:GetService("TeleportService"):Teleport(player, 31355192) end me.MouseButton1Click:connect(onClicked)