Well, you really need to put your code in a code block (that little blue Lua symbol) and tab it correctly.
Player = game.Players.LocalPlayer
Cave1 = script.Parent
Cave = game.Workspace.CaveTP
HasPressedCave1 = false
function TeleportPlayer()
if HasPressedCave1== false then
Player.Character(MoveTo(Cave.Position))
end
end
end
Teleport.MouseButton1Down:connect(TeleportPlayer)
There's five problems that will prevent your code from running. First, the Teleport variable you use in the connection line is nil. You never create it.
Second, you have two many ends. You only need two; one to close the function, one to close the if statement.
Third, you're using MoveTo() wrong. Since MoveTo() is a method or function of a model, we must call it on that model. To do that, we use a colon, or :. Then, in the following parentheses, we must give it a Vector3 to move the model to.
Fourth, the MouseButton1Down event is used for GUIs, but ClickDetectors use the MouseClick event.
Fifth, your LocalPlayer variable makes it look like this is in a LocalScript, but LocalScripts only run inside a character, PlayerGui, or Backpack. Therefore, we must use a server script. Getting the player will not be a problem, however, because MouseClick events have a built in parameter equal to the player who clicked it.
Place this script inside the ClickDetector and see how it works.
local clickDetector = script.Parent
local teleportBrick = workspace:WaitForChild("CaveTP")
script.Parent.MouseClick:connect(function(plr)
if plr.Character then
plr.Character:MoveTo(teleportBrick.Position)
end
end)
2 comments
Fix your codeblock please, then I can help.
Also what is CaveTP HasPressedCave1?