How to change head camera position in first person?

Hello everyone!

Today i tried make first persom, and i have this problem: Head camera have wrong position:

Script:

local self,player = script.Parent,game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local humanoid = char:WaitForChild("Humanoid") -- waits for the humanoid in the character



function antiTrans(part)
	if part and part:IsA("BasePart") and( part.Name=="LeftUpperArm"  or part.Name=="LeftLowerArm" or part.Name=="LeftHand" or part.Name=="RightUpperArm" or part.Name=="RightLowerArm" or part.Name=="LowerTorso" or part.Name=="UpperTorso" or part.Name=="RightLowerLeg" or part.Name=="RightUpperLeg" or part.Name=="RightFoor" or part.Name=="LeftLowerLeg" or part.Name=="LeftUpperLeg" or part.Name=="LeftFoot") then -- checks if a part and is a arm
		part.LocalTransparencyModifier = part.Transparency
		part.Changed:connect(function (property)    
			part.LocalTransparencyModifier = part.Transparency--Changes the local modifyer(client side only)
		end)
	end
end

for _,v in pairs(char:GetChildren()) do
	antiTrans(v) -- adds all parts
end

Have a nice day!

2 Likes

Hi
you can use the camera offset Value of the Players humanoid

local Humanoid = --your humanoid 
Humanoid.CameraOffset = -- Your Camera Offset

Have a nice day too

if it doesnt work just tag me

2 Likes

Working, but if player change camera to third person this happens:


@Linesgamer12

1 Like

Yes thats a problem you have to turn it off if you are in third person:

local requiredzoomdistance = .6       --<=== Change this to change the required zoom
------------------------------
local function FirstPersonCheck()
	local camera = game.Workspace.CurrentCamera
	local character = player.Character 
        if character == nil then return nil end
	local head = character:WaitForChild("Head")
        if (head.CFrame.p - camera.CFrame.p).magnitude <=  requiredzoomdistance then
        return true 
        else
        return false
        end 
end

this insnt 100% acurate but it should work just make it like this
if it starts to erly or to late just chage the:

local requiredzoomdistance = .6       --<=== Change this to change the required zoom

here is the whole code:

local requiredzoomdistance = .6       --<=== Change this to change the required zoom
------------------------------
local function FirstPersonCheck()
	local camera = game.Workspace.CurrentCamera
	local character = player.Character 
        if character == nil then return nil end
	local head = character:WaitForChild("Head")
        if (head.CFrame.p - camera.CFrame.p).magnitude <=  requiredzoomdistance then
        return true 
        else
        return false
        end 
end
game:GetService("RunService").PreRender:Connect(function()
local result = FirstPersonCheck()
if result ~= nil then
     if result then
          Humanoid.CameraOffset = --<== Your Camera Offset
          else 
             Humanoid.CameraOffset = Vector3.new(0,0,0)
          end
     end
end 
end)

this should work but if it doesnt just say me the errors its trowing

Have a nice day :smile:

3 Likes

I tried add this code and its not worked.

Script with pooted your part’s:

local requiredzoomdistance = .5
local self,player = script.Parent,game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local humanoid = char:WaitForChild("Humanoid")
function antiTrans(part)
	if part and part:IsA("BasePart") and( part.Name=="LeftUpperArm"  or part.Name=="LeftLowerArm" or part.Name=="LeftHand" or part.Name=="RightUpperArm" or part.Name=="RightLowerArm" or part.Name=="LowerTorso" or part.Name=="UpperTorso" or part.Name=="RightLowerLeg" or part.Name=="RightUpperLeg" or part.Name=="RightFoor" or part.Name=="LeftLowerLeg" or part.Name=="LeftUpperLeg" or part.Name=="LeftFoot") then
		part.LocalTransparencyModifier = part.Transparency
		part.Changed:connect(function (property)    
			part.LocalTransparencyModifier = part.Transparency
		end)
	end
end

for _,v in pairs(char:GetChildren()) do
	antiTrans(v)
end
local function FirstPersonCheck()
	local camera = game.Workspace.CurrentCamera
	if char == nil then return nil end
	local head = char:WaitForChild("Head")
	if (head.CFrame.p - camera.CFrame.p).magnitude <=  requiredzoomdistance then
		return true 
	else
		return false
	end 
end
game:GetService("RunService").PreRender:Connect(function()
	local result = FirstPersonCheck()
	if result ~= nil then
		if result then
			humanoid.CameraOffset = Vector3.new(0,0,-2)
		else 
			humanoid.CameraOffset = Vector3.new(0,0,0)
		end
	end
end)
1 Like

Hey I fixed it!
the new script ,Oh and I also fixed your non transparent body script:

local requiredzoomdistance = .65
local self,player = script.Parent,game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:wait()
local humanoid = char:WaitForChild("Humanoid")
function antiTrans(part)
	if part and part:IsA("BasePart") and( part.Name=="LeftUpperArm"  or part.Name=="LeftLowerArm" or part.Name=="LeftHand" or part.Name=="RightUpperArm" or part.Name=="RightLowerArm" or part.Name=="LowerTorso" or part.Name=="UpperTorso" or part.Name=="RightLowerLeg" or part.Name=="RightUpperLeg" or part.Name=="RightFoor" or part.Name=="LeftLowerLeg" or part.Name=="LeftUpperLeg" or part.Name=="LeftFoot") then
		part.LocalTransparencyModifier = part.Transparency
		part:GetPropertyChangedSignal("LocalTransparencyModifier"):Connect(function()  
			part.LocalTransparencyModifier = part.Transparency
		end)
	end
end
for _,v in pairs(char:GetChildren()) do
	antiTrans(v)
end
local function FirstPersonCheck()
	local camera = game.Workspace.CurrentCamera
	if not char then return nil end
	local head = char:WaitForChild("Head")
	if (char:WaitForChild("HumanoidRootPart").CFrame.Position+Vector3.new(0,2,0) - camera.CFrame.p-char:WaitForChild("HumanoidRootPart").CFrame.LookVector.Unit*humanoid.CameraOffset.Z).magnitude <=  requiredzoomdistance then
		return true 
	else
		return false
	end 
end
game:GetService("RunService").PreRender:Connect(function()
	local result = FirstPersonCheck()
	print(result)
	if result ~= nil then
		if result then
			humanoid.CameraOffset = Vector3.new(0,0,-1.5)
		else 
			humanoid.CameraOffset = Vector3.new(0,0,0)
		end
	end
end)

I hope it works on your game too, in the first version I was to lazy to test it ,and sorry for your eyes it looked very laggy.
Oh and I’m interested what kind of game you make so if everything is fine
I sadly won’t see you again but maybe someday you can help me so

5 Likes