im trying to make a script that makes the cam of the player to a part when he’s in first person
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local cam = Workspace.CurrentCamera
local Players = game:GetService("Players")
local plr = Players.LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait()
local head = chr:WaitForChild("Head")
local newPart = Instance.new("Part")
newPart.Name = "1PersonCam"
newPart.Parent = head
newPart.Size = Vector3.new(1, 1, 1)
newPart.CFrame = head.CFrame + Vector3.new(0, 0, -0.1)
newPart.Transparency = 1
newPart.CanCollide = false
local Weld = Instance.new("WeldConstraint")
Weld.Parent = newPart
Weld.Part0 = head
Weld.Part1 = newPart
local isInFirstPerson = false
RunService.RenderStepped:Connect(function()
local zoom = (cam.CFrame.Position - head.Position).Magnitude
if zoom < 1 then
if not isInFirstPerson then
isInFirstPerson = true
cam.CameraType = Enum.CameraType.Scriptable
end
cam.CFrame = newPart.CFrame
else
if isInFirstPerson then
isInFirstPerson = false
cam.CameraType = Enum.CameraType.Custom
end
end
end)
but the cam goes crazy when i do that, assuming i have somethin that makes the head match the cam rotation, how do i do this