CFrame tween not working

I have an NPC dialogue system (local script), I am trying to make the NPC turn to the player when a conversation starts, I currently have this code but the tween doesn’t work no matter what I do.

function torso_turn(char, subject) -- subject: the NPC's character
	local torso = subject:FindFirstChild("Torso")
	local root = char.HumanoidRootPart

	if torso then
		
		local new_cframe = CFrame.new(torso.Position, Vector3.new(root.Position.X, torso.Position.Y, root.Position.Z))
		
		local tween = TS:Create(torso, 
			TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut),
			{
				CFrame = new_cframe
			}
		)
		tween:Play()
        -- the CFrame \/, it works if I run this line but I want it smooth :(
		-- torso.CFrame = CFrame.new(torso.Position, Vector3.new(root.Position.X, torso.Position.Y, root.Position.Z))
	end
end

I have tried setting it to other CFrames but those don’t work either, this tween for some reason just refuses to tween CFrames, it works just fine if you change orientation/position of the torso via tween.

Thanks in advance.

1 Like

To tween CFrames, you need to use ["CFrame"] = CFrame as CFrame is a already declared variable, so writing it as a string causes it to work.

Heres some fixed code:

local tween = TS:Create(torso, 
			TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.InOut),
			{
				["CFrame"] = new_cframe
			}
		)

Also tween the root part, not the torso as @JamminRedPandaMan said

Have you tried tweening the HumanoidRootPart of the NPC rather than the torso? Typically when I’m dealing with character orientation, setting CFrame by the HumanoidRootPart seems to work better than torso.

1 Like

That’s so stupid, I don’t understand why torso just refuses to work, but yeah, it works with the root.

1 Like

I’ve tweened CFrames by doing what I was doing many times.

1 Like

I believe that what @Chark_Proto suggested is the technical way to set an index, but ROBLOX made our lives a little easier by not requiring it when writing a property table for Tween Service.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.