Hey everyone! So, I have this script that teleports all players to a part, which works as intended. However, I also want them to face the same direction as the part. How would I implement that in this code snippet?
if lobby:FindFirstChild("Spawn") then
local c = game.Players:GetChildren()
for i = 1, #c do
if c[i].Character ~= nil and c[i].Character:FindFirstChild("HumanoidRootPart") then
c[i].Character:PivotTo(lobby.Spawn.CFrame) -- how do i make the player face the right way?
end
end
end
If you’re matching the player character’s CFrame to the spawner, then you can just physically rotate the spawner so that it faces the direction that you want the player to face.
I have tried rotating it, but it keeps facing the same way. But since this is the player’s character model, I am not really sure how to rotate the player so they face the correct direction.
Are you certain that the code is even executing? If you set one object’s CFrame to another’s, they’ll match their rotation and position. So rotating the spawner would also rotate the player. Or there could be a timing issue, but that’s unlikely.
I am sure the code is executing. If it didn’t, then I wouldn’t even spawn in the level to begin with. Also, I put a print statement just in case and it did execute.
Either your script isn’t working correctly or you’ve got a conflict with something else. You could try adding a slight delay before moving the character and that would be a hacky way of fixing timing-related issues.
oh in that case then I’m out of ideas, because my other idea was to make it so that the character refresh (loadcharacter), then teleport them to the part
After some testing, it seems that nothing is broken. All you need to do is set the CFrame of the camera too. You can either set it the same way as the character, or you can give it that CFrame.Angles(0,math.rad(90),0) offset.
Ok so after some tweaking, I have found the solution to my question. Basically, I decided to use a remote event to set the camera to the part’s CFrame while using :PivotTo() to teleport the player.
ServerSided Script:
for i = 1, #c do
if c[i].Character ~= nil and c[i].Character:FindFirstChild("HumanoidRootPart") then
c[i].Character:PivotTo(lobby.Spawn.CFrame)
game.ReplicatedStorage.RotateCamera:FireClient(c[i], lobby.Spawn.CFrame)
end
end