First, you must declare the function to teleport the player.
function onClick()
local teleportService=game:GetService("TeleportService")
teleportService:Teleport(211564635)
end
Then you must connect this function to an event. An event lets you call a function (run it) whenever something specific happens. MouseButton1Click is an event of TextButtons (as you'll see near the bottom). So, we can connect our function to this event so the function runs when the event happens. Like this:
script.Parent.MouseButton1Click:connect(onClick)
Full script:
function hello()
local teleportService=game:GetService("TeleportService")
teleportService:Teleport(211564635)
end
script.Parent.MouseButton1Click:connect(hello)
4 comments
It still does not work. I tried in a Script, and it won't teleport me! Help?
Make sure it's a LocalScript
It still doesn't work! I don't know why!
It has to be a LocalScript in a TextButton, and that TextButton should probably be in a ScreenGui, and that ScreenGui has to be in StarterGui. It works fine for me, even though it won't let me teleport to your game because it's not my game.