Hello i'm new to scripting. Was trying to make a script that would make the player face the camera's look vector. Found a lot of examples online but this one was the most simplest for me. however i'm still confused. Was wondering about the difference between those two lines below? why did "root,CFrame.P" get assigned the second time inside the vector in example 1? Most importantly why is example 2 incorrect? Thank u
----Example 1 (correct one)
local cam = workspace.CurrentCamera
local plr = game:GetService("Players").LocalPlayer
local root = plr.Character.HumanoidRootPart
game:GetService("RunService").RenderStepped:connect(function()
if plr.Character then
root.CFrame = CFrame.new(root.CFrame.p,root.CFrame.p+Vector3.new(cam.CFrame.lookVector.X,0,cam.CFrame.lookVector.Z))
end
end)
----Example 2 (Wrong one)
local cam = workspace.CurrentCamera
local plr = game:GetService("Players").LocalPlayer
local root = plr.Character.HumanoidRootPart
game:GetService("RunService").RenderStepped:connect(function()
if plr.Character then
root.CFrame = CFrame.new(root.CFrame.p, Vector3.new(cam.CFrame.lookVector.X,0,cam.CFrame.lookVector.Z))
end
end)

3 comments
Thank you so much! But wouldn't problem 2 be solved/valid if i were to use " :ToObjectSpace() " when setting the camera's value then? if so how would u use it? Thank u in advance
Hey! thank u so much for helping me! I really appreciate it and it means a lot to me, i mean it! i hope you have a good rest of your day and blessings come your way!
You'd want to use :toWorldSpace in this example, root.CFrame:toWorldSpace(CFrame.new(cam.CFrame.lookVector)) [I think]