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

Button that teleports you somewhere ingame is not working. Help with fixing it?

Asked by 4 years ago

I'm trying to make an easter egg with a button, that when clicked, it teleports you to somewhere in the game. However, it's not working. Can someone help me fix it?

To start off, it's a LocalScript, within a ClickDetector, within the part that's the button.

Script itself:

local players = game:GetService("Players")

local localPlayer = players.LocalPlayer

local tpposition1 = script.Parent.Parent.Parent.Parent.TPpart.Position

script.Parent.MouseClick:Connect(function() localPlayer:MoveTo(tpposition1) end)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

There are some things wrong here. 1.) You have to use a ServerScript. Otherwise, it wouldn't teleport you unless you used a RemoteEvent. 2.) A LocalScript can only be run when it's under a Player's Gui or Starter Scripts. Not parts. Also, the player can be obtained using the ClickDetector parameter. Try this:

local clickDetector = script.Parent:WaitForChild("ClickDetector")

local teleportPosition1 = script.Parent.Parent.Parent.Parent:WaitForChild("TPpart").Position

clickDetector.MouseClick:Connect(function(player)
    player.Character:MoveTo(teleportPosition1)
end)

Hopefully, this helps you.

Ad

Answer this question