Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

GUI teleportation script help how to find a player?

Asked by 7 years ago

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

Log in to vote
0
Answered by 7 years ago

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.

Ad
Log in to vote
0
Answered by
Mayk728 855 Moderation Voter
7 years ago
Edited 7 years ago

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.

Answer this question