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

GUI teleportation script help how to find a player?

so im trying to make a GUI teleport script and here is what i got

function teleport()

workspace.player1:MoveTo(workspace.tp1)


end
script.Parent.MouseButton1:connect(teleport)

it works but if i published this on roblox then "player1" wouldnet work how do i make my script use whoever pushed the buttons username?

2 answers

Every LocalScript has a built-in property called LocalPlayer. In order to access this, you can just say something like

Player = game.Players.LocalPlayer

You can then use the variable Player within your LocalScript's functions to access the player.

If you're trying to make a teleport Gui, you should use a LocalScript. When you teleport the Player you should move their HumanoidRootPart using CFrame. MoveTo is to actually walk a player or NPC to the desired part, which is probably what you don't want. Also, when you try to move the player, you used Player1 which will only try to find Player1 instead of whoever clicks on the button. Here is the fixed script.

function teleport()

game.Players.LocalPlayer.Character.HumanoidRootPart.CFrame = CFrame.new(workspace.tp1.Position)

end

script.Parent.MouseButton1Click:connect(teleport)

Once again, you should use a LocalScript, not a normal Server Script.

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