I am making an elevator and when a player clicks a button it teleports them but it doesn't work. There are no errors in the output.
Script:
wait(1) player = game.Players.LocalPlayer function teleport() torso = player.Character.Torso torso.CFrame = CFrame.new(game.Workspace.Floor2Ele.Part.CFrame) end script.Parent.ClickDetector.MouseClick:connect(teleport)
One easier way is the usage of MoveTo
.
wait(1) player = game.Players.LocalPlayer function teleport() local c = player.Character c:MoveTo(workspace.Floor2Ele.Part.Position) end script.Parent.ClickDetector.MouseClick:connect(teleport)
The problem with using CFrame is unanimous to me, although I can recall some occurrences.
I realized that you didn't clarify if the syntax was either located in a script
or localscript
. If it was script
then here's the right syntax.
function teleport(player) local c = player.Character c:MoveTo(workspace.Floor2Ele.Part.Position) end script.Parent.ClickDetector.MouseClick:connect(teleport)