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