✓ Accepted answer
Using MoveTo isn't the way to do this, all parts will move with the hrp, so just rotate/move the hrp to teleport a player
(HRP = HumanoidRootPart)
For this, use CFrame
Btw, use remote events, don't teleport client side
Player = game.Players.LocalPlayer
SpawnTo = game.Workspace.SpawnTele
TeleportButton = script.Parent.TeleportButton
HasPressedTeleport = false
function TeleportPlayer()
if HasPressedTeleport == false then
local char = Player.Character
if char then
local HRP = char:WaitForChild('HumanoidRootPart')
HRP.CFrame = SpawnTo.CFrame
end
end
end
TeleportButton.MouseButton1Down:connect(TeleportPlayer)
If you have any question, or I made a typo/mistake, just ask :)
So as an edit for your question, the best way to do it is to set the camera quickly to attach, then back to custom
Player = game.Players.LocalPlayer
SpawnTo = game.Workspace.SpawnTele
TeleportButton = script.Parent.TeleportButton
HasPressedTeleport = false
local Cam = workspace.CurrentCamera
function TeleportPlayer()
if HasPressedTeleport == false then
local char = Player.Character
if char then
local HRP = char:WaitForChild('HumanoidRootPart')
HRP.CFrame = SpawnTo.CFrame
repeat
wait()
Cam.CameraType = Enum.CameraType.Attach
until Cam.CameraType == Enum.CameraType.Attach
repeat
wait()
Cam.CameraType = Enum.CameraType.Custom
until Cam.CameraType == Enum.CameraType.Custom
end
end
end
TeleportButton.MouseButton1Down:connect(TeleportPlayer)
10 comments
Thank you for the speedy response! I'm pretty new to a lot of this so I'm unsure what you mean on line 13, and I don't know what to add there.
CFrame (CoordinatedFrame) is just a Player's position and Rotation combined, The CFrame is more accurate than Vector3 (X,Y,Z only) because Vector3 mostly teleports you on top of things and doesn't has a rotation in it, by setting your HRPs CFrame to the part's CFrame you set your rotation as the rotation of the part so you can choose how you're rotated on spawn, hope this helps lol
You don't have to add anything, just rotate the spawnpart to change the player's rotation :)
Ah I understand! Sorry for being so clueless haha. So the character faces the correct way, but the camera doesn't rotate with them. Would this be an easy fix? I'm so sorry for all the questions ;o;
That would be hard to do, read this --> http://wiki.roblox.com/index.php?title=API:Class/Camera (btw, please accept my answer :))
Aw, okay. Thanks for your time.
I edited the script, now it should rotate with you :)
(It works by setting the camera quickly to attached and then back to custom)
Thank you so much! It works!
Np :)