Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Game teleport onclick of a surface Gui textbutton not working?

I am using the teleport service. This is a normal script placed inside of the textbutton in the surfaceGui. I am not quite sure why it is not responding.

script.Parent.MouseButton1Down:connect(function()
	game:service("TeleportService"):Teleport(MYGAMEIDHERE)
end)

This is the script. It's pretty simple

3 answers

local player = game.Players.LocalPlayer
local GameId = YourGameIdHere

script.Parent.MouseButton1Down:connect(function() 
    game:service("TeleportService"):Teleport(GameId, player)
end)

You need to declare the player, because teleportService use two parametre, the first parametre is the game Id for know where the player will go and the second is the player for know wich player will be teleport. Put it in a LocalScript for declaring the player with no error !


script.Parent.MouseButton1Down:connect(function(player) 
    game:service("TeleportService"):Teleport(MYGAMEIDHERE, player)
end) 

The teleport method needs to know who to teleport. However, because your surface gui is not under a playerGui folder, it can't tell who clicked. To get around this, put the surfaceGui in StarterGui, and set the "Adornee" property to the brick you want.

This discussion is preserved as it was. New answers, comments, and votes are closed.