You can write your topic however you want, but you need to answer these questions:
What do you want to achieve? Keep it simple and clear!
I want to rotate a player 180° when he gets teleported
What is the issue? Include screenshots / videos if possible!
Whenever I try to use CFrame.Angles the player gets teleported somewhere and not rotated
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
Using CFrame.Angles, setting the cframe to a new cframe of the current position of the player + CFrame.Angles
--jmp1 and jmp2 are characters of the players
jmp1:SetPrimaryPartCFrame(CFrame.new(141.275, 567.343, -320.41)) --jmp's get teleported
jmp2:SetPrimaryPartCFrame(CFrame.new(141.275, 567.343, -373.633))
--I need the rotation to happen here to jmp2 by 180°
Please do not ask people to write entire scripts or design entire systems for you. If you can’t answer the three questions above, you should probably pick a different category.
try it in this way, I’ll give you two codes, one with TweenService and other without, cause using tweenservice can help you make it look like it was smooth.
Without TweenService: (it instantly turns the player 180 degrees)
local hrp1=jmp1:FindFirstChild("HumanoidRootPart")
local hrp2=jmp2:FindFirstChild("HumanoidRootPart")
if hrp1 and hrp2 then
hrp1.CFrame=hrp1.CFrame * CFrame.Angles(0,math.rad(180),0)
hrp2.CFrame=hrp2.CFrame * CFrame.Angles(0,math.rad(180),0)
end
Using TweenService: (Its smooth, you can adjust the time taken and tween styles using tween info parameters)
local hrp1=jmp1:FindFirstChild("HumanoidRootPart")
local hrp2=jmp2:FindFirstChild("HumanoidRootPart")
local tweenService=game:GetService("TweenService")
local tweenInfo=TweenInfo.new(0.5,Enum.EasingStyle.Linear,Enum.EasingDirection.Out)
if hrp1 and hrp2 then
tweenService:Create(hrp1,tweenInfo,{CFrame=hrp1.CFrame * CFrame.Angles(0,math.rad(180),0)}):Play()
tweenService:Create(hrp2,tweenInfo,{CFrame=hrp2.CFrame * CFrame.Angles(0,math.rad(180),0)}):Play()
end
this should help! let me know if theres something wrong.
Oh you should have specified that it was a firstperson game, what you could do is, use a LocalScript to just manipulate the camera to turn 180 degrees and it should work. Cause its in firstperson, it should also rotate the character with camera.
Use remote events, and do :FireClient() and use this code in localscript using OnServerEvent :
Maybe it has something to do when I made the camera scriptable?
I could maybe also do something like this but I’m not sure it’ll work.
My camera is fixed to the head of the player so I maybe if I move the camera it’ll also move the head?
local camera = game.Workspace.CurrentCamera
local Player = game.Players.LocalPlayer
local character = Player.Character
local head = character:WaitForChild("Head")
camera.CoordinateFrame = CFrame.new(head.Position) * CFrame.Angles(0,math.rad(180),0)
Yeah also, if you are using any framework using RunService to keep changing the cameras CFrame, it’ll be overriding anything else as RenderStepped runs like what, 60 times a second?, that might be why?
Ok, I got it to work, what I did was set an attribute on the character called ‘Teleport’ and in a local script I check for this attribute being changed, and when it is changed, I set the camera cframe from it
local start = script.Parent
local beam = start:WaitForChild("Beam")
local stop = beam.Attachment1.Parent
local decal = stop:WaitForChild("Decal")
local debounce = false
start.Transparency = 1
stop.Transparency = 1
beam.Enabled = false
decal.Transparency = 1
start.Touched:Connect(function(part)
if not debounce then
debounce = true
local player = game.Players:GetPlayerFromCharacter(part.Parent)
if player and part.Parent:FindFirstChild("Humanoid") then
local char = part.Parent
local hrp = char.PrimaryPart
local humanoid = char.Humanoid
local cf = stop.CFrame + Vector3.new(0,(stop.Size.Y/2)+(hrp.Size.Y/2)+humanoid.HipHeight ,0)
char:SetAttribute("Teleport",cf)
char:PivotTo(cf)
wait(.3)
end
debounce = false
end
end)
script.Parent:GetAttributeChangedSignal("Teleport"):Connect(function()
local cf = script.Parent:GetAttribute("Teleport")
script.Parent:PivotTo(cf)
workspace.CurrentCamera.CFrame = cf
end)