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

Why wont this Teleport players to the game?

It is suppose to Teleport them to the place after clicking a GUI button

player = game:FindFirstChild("Player")

function onButtonClicked()

game:GetService("TeleportService"):Teleport(101314122, player)
end

script.Parent.MouseButton1Down:connect(onButtonClicked)

2 answers

You need to define player by indexing the LocalPlayer of game.Players.


local player = game.Players.LocalPlayer

function onButtonClicked()
	game:GetService("TeleportService"):Teleport(101314122, player)
end

script.Parent.MouseButton1Down:connect(onButtonClicked)

NOTE: This should be used in a LocalScript.

Accessing the Player

There are many ways to access the player.

  • PlayerAdded(function)

  • LocalPlayer(property of player)

LocalPlayer, only works on a LocalScript, PlayerAdded on the other hand, only works on a ServerScript(Script). But right Now I'll be using LocalPlayer.

local player = game.Players.LocalPlayer

function onButtonClicked()
	game:GetService("TeleportService"):Teleport(101314122, player)
end

script.Parent.MouseButton1Down:connect(onButtonClicked)

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