Issue with :teleportService

Code
--Version 1--
local GameId = 6681677122

script.Parent.MouseButton1Click:connect(function(player)
game:GetService('TeleportService'):Teleport(GameId, player)

end)
--Version 2--
local GameId = 6681677122
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
	game:GetService('TeleportService'):Teleport(GameId, player)
end) 
--Version 3 --
local GameId = 6681677122
local player = game.Players.LocalPlayer

script.Parent.MouseButton1Click:connect(function()
	game:GetService('TeleportService'):Teleport(GameId, game.Players.LocalPlayer)
end) 
  1. I’m trying to make it when a user clicks a ScreenUI button I have in my main game, it teleports the user to a different place(the main game).
  2. Every time I run the code, no matter how I define my player it errors me saying that it’s a invalid player to teleport.
    3.I have defined my player 3 ways and all of them failed. I tried defining it through function, vars, and just a string. I can’t tell if its my code or because I have a display name.
    Any help is appreciated!

Is it a local script?

:man_facepalming: Of course I make a whole devforum post on this and realize I forgot to make it local xd. Thanks, I knew the code was right.

1 Like

Yeah the code is correct, using stuff that has to do with gui is done with a local script.