"Unable to cast to dictionary" error in tween

I’m trying to make a script that moves your head along with the camera when the camera moves but it’s still moving the head but it keeps giving me this error. Is there any way I can fix this? Thanks.

local camera = workspace.CurrentCamera

local char = game.Players.LocalPlayer.Character
local root = char:WaitForChild("HumanoidRootPart")
local Neck = char:FindFirstChild("Neck", true)
local YOffset = Neck.C0.Y


game:GetService("RunService").RenderStepped:Connect(function()
	local CameraDirection = root.CFrame:ToObjectSpace(camera.CFrame).LookVector
	local CFNew, CFAng, asin = CFrame.new, CFrame.Angles, math.asin

	if Neck then
		task.wait(0.1)
		local ts = game:GetService("TweenService")
		
		local tInfo = TweenInfo.new(
			0.25,
			Enum.EasingStyle.Sine,
			Enum.EasingDirection.InOut,
			0,
			false,
			0
		)
		
		local goal = {
			CFNew(0, YOffset, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(0, 0, -asin(CameraDirection.x)) * CFAng(-asin(CameraDirection.y), 0, 0)
		}
		local tween = ts:Create(Neck.C0, tInfo, goal) --I'm getting the errror from this line
	end
end)
1 Like

you should do

local goal = {
    CFrame = CFNew(0, YOffset, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(0, 0, -asin(CameraDirection.x)) * CFAng(-asin(CameraDirection.y), 0, 0)
}

Hmm, still not working! It gives the same error.

sorry about that (I wasn’t paying attention) I meant:

local goal = {
			C0 = CFrame.new(0, YOffset, 0) * CFrame.Angles(3 * math.pi/2, 0, math.pi) * CFrame.Angles(-math.asin(CameraDirection.y), 0, -math.asin(CameraDirection.x))
		}

but also after looking at your code I’m pretty sure you got the math wrong

I fixed it already sorry. I just used lerping instead of tweening.

But it is the same math though right? I just want to know what I did wrong with the tweening

local camera = workspace.CurrentCamera

local char = game.Players.LocalPlayer.Character
local root = char:WaitForChild("HumanoidRootPart")
local Neck = char:FindFirstChild("Neck", true)
local YOffset = Neck.C0.Y


game:GetService("RunService").RenderStepped:Connect(function()
	local CameraDirection = root.CFrame:ToObjectSpace(camera.CFrame).LookVector
	local CFNew, CFAng, asin = CFrame.new, CFrame.Angles, math.asin

	if Neck then
		for i = 0,0.03,.01 do
			task.wait()
			Neck.C0 = Neck.C0:Lerp(CFNew(0, YOffset, 0) * CFAng(3 * math.pi/2, 0, math.pi) * CFAng(0, 0, -asin(CameraDirection.x)) * CFAng(-asin(CameraDirection.y), 0, 0), i)
		end
	end
end)

This line shouldn’t work like that. You would have to wait before all this and you must be doing that or this would error.

Try this, head is facing forward with a broken neck … is that what you wanted?

local camera = workspace.CurrentCamera
local plr = game:GetService("Players").LocalPlayer
local chr = plr.Character or plr.CharacterAdded:Wait()
local root = chr:WaitForChild("HumanoidRootPart")
local Neck = chr:FindFirstChild("Neck", true)
local YOffset = Neck.C0.Y

game:GetService("RunService").RenderStepped:Connect(function()
	local CameraDirection = root.CFrame:ToObjectSpace(camera.CFrame).LookVector
	local CFNew, CFAng, asin = CFrame.new, CFrame.Angles, math.asin

	if Neck then
		task.wait(0.1)
		local ts = game:GetService("TweenService")

		local tInfo = TweenInfo.new(
			0.25,
			Enum.EasingStyle.Sine,
			Enum.EasingDirection.InOut,
			0,
			false,
			0
		)

		local goal = CFrame.new(0, YOffset, 0) * CFrame.Angles(3 * math.pi/2, 0, math.pi) * CFrame.Angles(0, 0, -asin(CameraDirection.x)) * CFrame.Angles(-asin(CameraDirection.y), 0, 0)

		-- Adjust the rotation to face forward (modify the angles as needed)
		goal = goal * CFrame.Angles(0, math.pi, 0) -- Rotates 180 degrees around Y axis

		-- Create and play the tween
		local tween = ts:Create(Neck, tInfo, {C0 = goal})
		tween:Play()
	end
end)

That line should be …
local chr = plr.Character or plr.CharacterAdded:Wait()

If anything else this is a great zombie look.

It’s not a good idea to animate a Motor6D’s C0 or C1 offsets. Motor6D have another property called .Transform which is specifically optimized for animations. You should be using that instead.

I can’t get it to work without that head being tilted back … 90% there too. Good luck!
On the other hand you made a great Zombie look.

Is this more easier to use? Because I don’t really understand how to use this

Should be simplier than animating C0 and C1. It is what you’re SUPPOSED to be using for animation in the first place.