CFrame camera not moving

Hello developers!
Today I was trying to make npc/dummy talk to you. I tried to make camera go to his head with CFrame but it didn’t work and I don’t know why, (I am new at scripting thats probably why) i am gonna put script under below and if someone knows what it is i would be more than happy to know :slight_smile:

have a good day!

Part of script that contains CFrame (no errors occur in output, it just doesn’t move)

	if Chatting == true then
		local Humanoid = detectedNPC:FindFirstChild("Humanoid")
		local HMR = detectedNPC:FindFirstChild("HumanoidRootPart")

		if Humanoid and HMR then
			camera.CameraType = Enum.CameraType.Scriptable
			camera.CFrame = camera.CFrame:Lerp(HMR.CFrame * CFrame.new(-4, 4, -7) * CFrame.fromOrientation(math.rad(-20), math.rad(215), 0), 0,07)
		end
	else
		camera.CameraType = Enum.CameraType.Custom
	end

Is this in a script or a localscript? The camera can only be manipulated on the client

1 Like

hello. devforum is glitching for me , yes this is a localscirpt.

Are there any errors in the output?

there are no errors in output.

Alright, if there are no errors and the code is running, that likely means that the math for the CFrame just isn’t what you want. Does your camera move anywhere when this code is running by the way?

camera is not moving not even a little bit. i don’t know why that occures

Oh, you could try testing with print() to see if it registers when chatting is true and when the camera CFrame needs to change as well.

even if i try with printing it won’t fix the problem sadly.

If the CameraType is being set to Scriptable when you test it it is most likely the CFrame math
Maybe try this more basic code as a test

if Humanoid and HMR then
		camera.CameraType = Enum.CameraType.Scriptable
		camera.CFrame = HMR.CFrame * CFrame.new(0, 2, -2)
end
1 Like

I was just making sure that the camera CFrame code is actually running by adding a print.

1 Like

i tried that but it doesnt contain any smooth moving animations, it does change camera(good point)

You can try using TweenService to get the smooth effect.
Put local TS = game:GetService("TweenService") at the top of the script, and then change the camera CFrame bit to this.

TS:Create(camera, TweenInfo.new(1), {CFrame = HMR.CFrame * CFrame.new(0, 2, -2)}):Play()

The 1 in the TweenInfo is the amount of seconds it takes to interpolate

thanks. I tried it but in output is says: " [ Players.SuccessfuIDev.PlayerGui.TalkGui2.LocalScript:147: attempt to call a TweenInfo value]"

Ah my bad forgot the comma after TweenInfo.new(1)

1 Like

thanks you saved me, i would research how to fix that for hours. :smiley:

1 Like

actually one question left that i wanna ask. How could i put rotation in that CFrame camera because it’s facing dummy’s back now. still thanks.

Maybe try changing the CFrame.new(0, 2, -2) to CFrame.new(0, 2, 2)

I did that but the camera doesn’t rotate it just goes straight up

I think this should flip the view of the camera

TS:Create(camera, TweenInfo.new(1), {CFrame = HMR.CFrame * CFrame.new(0, 1.5, -2) * CFrame.Angles(0, math.pi, 0)}):Play()

1 Like