Im making this game on roblox, and I cant seem to find a way to make my button teleport the player. This is the code I want to put the teleport into:
local function OnClicked() script.Parent.Parent:Remove() end script.Parent.MouseButton1Click:connect(OnClicked)
Its part of a menu, where when you click the button, its supposed to close out the GUI and teleport you to an XYZ coordinates. I have the part to close out the GUI, but I cant find out how to make to teleport the player!
To do this there is a very useful method called MoveTo which can be called on any model.
MoveTo takes one parameter which is the Vector3 position
Here you can call MoveTo on the player character's model to move it to a certain Vector3 position
A way to get the player and the player's character in a local script, and only in a local script is by game.Players.LocalPlayer and then game.Players.LocalPlayer.Character to get the player's character
So since this is a local script, we can set up the variables like this:
Note: using the localplayer method only works for local scripts
local player = game.Players.LocalPlayer local character = player.Character
Now that you set up the variables you can go ahead and move the player's character
local function OnClicked() script.Parent.Parent:Destroy() -- remove is deprecated, use Destroy instead character:MoveTo(Vector3.new(0, 5, 10)) -- assuming this is the vector3 position end script.Parent.MouseButton1Click:connect(OnClicked)
Hope it helped!