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)
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.
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)