Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to make a player face a certain direction when they teleport?

When a player teleports, I would like for them to face a toward a fixed spot, but I'm not sure how. Is there a way to do this?

This script is to teleport the player to an area when they click a button on a gui. If the solution could be implemented within this script that would be great!

Player = game.Players.LocalPlayer
SpawnTo = game.Workspace.SpawnTele
TeleportButton = script.Parent.TeleportButton
HasPressedTeleport = false


function TeleportPlayer()
	if HasPressedTeleport == false then
		Player.Character:MoveTo(SpawnTo.Position)
		wait(0.1)
	
	end
end

TeleportButton.MouseButton1Down:connect(TeleportPlayer)

1 answer

✓ 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 -- Might not be loaded
		local HRP = char:WaitForChild('HumanoidRootPart')
		HRP.CFrame = SpawnTo.CFrame -- You can rotate 'spawnto' to change the players rotation or use cframe angles
	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 -- Might not be loaded
		local HRP = char:WaitForChild('HumanoidRootPart')
		HRP.CFrame = SpawnTo.CFrame -- You can rotate 'spawnto' to change the players rotation or use cframe angles

		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

0

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.

0

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

0

You don't have to add anything, just rotate the spawnpart to change the player's rotation :)

0

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;

0

That would be hard to do, read this --> http://wiki.roblox.com/index.php?title=API:Class/Camera (btw, please accept my answer :))

0

Aw, okay. Thanks for your time.

0

I edited the script, now it should rotate with you :)

0

(It works by setting the camera quickly to attached and then back to custom)

0

Thank you so much! It works!

0

Np :)

This discussion is preserved as it was. New answers, comments, and votes are closed.