Hello, I'm trying to code a Player Teleportation script for an OnClicked Gui to teleport to my game. The code is below.
1 | function OnClicked() |
2 | script.Disabled = true |
3 | local player = script.Parent.Parent.Parent.Parent |
4 | if player then |
5 | game:GetService( "TeleportService" ):Teleport( 361416851 , player) |
6 | end |
7 | end |
8 |
9 | script.Parent.MouseButton 1 Click:connect(OnClicked) |
Why does this not work in a game? If someone can help me, that'd be great!
You're trying to shut down the script before you can do anything. Move line 2 down to line 5 and it should work. Good luck!