Camera doesn't follow in crouching script

I was just wondering how I could make the camera of my character follow the character’s head when I press the crouch button. I’ve tried different methods such as camera.CameraSubject = head. This does work except that this would happen

. This is my current code
local uis = game:GetService(“UserInputService”)
local char = script.Parent
local hum = char:WaitForChild(“Humanoid”)
local isCrouching = false
local animation = hum:LoadAnimation(script:WaitForChild(“Animation”))
local HipHeight = hum.HipHeight

uis.InputBegan:connect(function(key)
if key.KeyCode == Enum.KeyCode.LeftControl then
if not isCrouching then
isCrouching = true
animation:Play()
hum.WalkSpeed = 9
hum.JumpPower = 0
HipHeight = 1
else
HipHeight = -1
animation:Stop()
hum.WalkSpeed = 14
hum.JumpPower = 50
isCrouching = false
end
end
end)

I’ve tried messing around with hip height to see if that works, It didn’t

There’s a property in the Humanoid object called CameraOffset. By adjusting its Y value, you can move the camera up and down.

2 Likes

So this did work in live studio put when I put it in code, should I use CFrame or what?

No, the CameraOffset property uses a Vector3 value

Thank you for helping me, it now works!